Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Yasuo Ohgaki : > Hi, > > 2012/8/22 Peter Cowburn : >> On 21 August 2012 23:26, Yasuo Ohgaki wrote: >>> array_walk is the best(fast and memory efficient) way >>> to delete elements. >> >> If array_walk() is the best (fast and memory efficient) way to delete >> elements, why have we had the following line in the manual, for the >> array_walk() callback, for over a decade [1]? (The exact phrasing has >> changed slightly one time, but the message has remained the same) >> "Only the values of the array may potentially be changed; its >> structure cannot be altered, i.e., the programmer cannot add, unset or >> reorder elements." >> >> [1] http://svn.php.net/viewvc/?view=revision&revision=75124 > > 10 years ago log :) > I'm not sure, but it had some problems with reference back then. > There were many array functions that behaved wrong with reference > used to be. > > I was annoyed by that, probably. That's why I wrote it, I suppose. > > Good catch. > It should be removed now. I thought it's in there now, but it's not. What's the point of bring up old bug documentation now? I really don't see. Regards, -- Yasuo Ohgaki -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Levi Morrison : >> Why did you change the equivalent code? >> array_walk is the best(fast and memory efficient) way >> to delete elements. >> >> This code may be refereed from old PHP users, therefore >> we should write better code. >> >> If you don' t have good reason to do so, please revert >> the change. > > The implementation you had may be faster, but that is certainly NOT > what matters as long as both are correct. What matters in the RFC is > clarity. You have already said that too many people don't know about > array_walk, so why would they understand array_delete in terms of > array_walk? Please do not revert the change as what I have written is > more clear. I don't say array_walk() is difficult, but people out there just don't know it. Why we should use inefficient example for internals? Besides, if array_walk() is used, people who would like to write patch for it will knew that most of code can be borrowed from array_walk(). Thus, it may prevent reinventing wheel. > The reason speed doesn't matter in behavior example is that once it is > implemented in C it will be just as fast as array_walk, perhaps it > will even be faster. I cannot agree to this opinion. I still think the example should be reverted. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/22 Peter Cowburn : > On 21 August 2012 23:26, Yasuo Ohgaki wrote: >> array_walk is the best(fast and memory efficient) way >> to delete elements. > > If array_walk() is the best (fast and memory efficient) way to delete > elements, why have we had the following line in the manual, for the > array_walk() callback, for over a decade [1]? (The exact phrasing has > changed slightly one time, but the message has remained the same) > "Only the values of the array may potentially be changed; its > structure cannot be altered, i.e., the programmer cannot add, unset or > reorder elements." > > [1] http://svn.php.net/viewvc/?view=revision&revision=75124 10 years ago log :) I'm not sure, but it had some problems with reference back then. There were many array functions that behaved wrong with reference used to be. I was annoyed by that, probably. That's why I wrote it, I suppose. Good catch. It should be removed now. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21 August 2012 23:26, Yasuo Ohgaki wrote: > array_walk is the best(fast and memory efficient) way > to delete elements. If array_walk() is the best (fast and memory efficient) way to delete elements, why have we had the following line in the manual, for the array_walk() callback, for over a decade [1]? (The exact phrasing has changed slightly one time, but the message has remained the same) "Only the values of the array may potentially be changed; its structure cannot be altered, i.e., the programmer cannot add, unset or reorder elements." [1] http://svn.php.net/viewvc/?view=revision&revision=75124 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
> Why did you change the equivalent code? > array_walk is the best(fast and memory efficient) way > to delete elements. > > This code may be refereed from old PHP users, therefore > we should write better code. > > If you don' t have good reason to do so, please revert > the change. The implementation you had may be faster, but that is certainly NOT what matters as long as both are correct. What matters in the RFC is clarity. You have already said that too many people don't know about array_walk, so why would they understand array_delete in terms of array_walk? Please do not revert the change as what I have written is more clear. The reason speed doesn't matter in behavior example is that once it is implemented in C it will be just as fast as array_walk, perhaps it will even be faster. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/22 Levi Morrison : > On Tue, Aug 21, 2012 at 4:13 PM, Yasuo Ohgaki wrote: >> Hi, >> >> I see why with new Criticism section in the wiki page. >> You've also misunderstood that array_udelete() is >> array_walk() variant, not array_filter(). >> > > Actually, array_udelete is far more similar to array_filter than it is > array_walk. . . Why did you change the equivalent code? array_walk is the best(fast and memory efficient) way to delete elements. This code may be refereed from old PHP users, therefore we should write better code. If you don' t have good reason to do so, please revert the change. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/22 Levi Morrison : > On Tue, Aug 21, 2012 at 4:13 PM, Yasuo Ohgaki wrote: >> Hi, >> >> I see why with new Criticism section in the wiki page. >> You've also misunderstood that array_udelete() is >> array_walk() variant, not array_filter(). >> > > Actually, array_udelete is far more similar to array_filter than it is > array_walk. . . Have you read my posts in this thread? Array filter CREATES new array instead of deleting elements. If one would like to DELETE element(s) by element value, array_walk is the way to go. I suppose I don't have to explain memory and execution efficiency here. Many people misunderstand the best practice. This is the reason why I think there should be array_udelete. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Tue, Aug 21, 2012 at 4:13 PM, Yasuo Ohgaki wrote: > Hi, > > I see why with new Criticism section in the wiki page. > You've also misunderstood that array_udelete() is > array_walk() variant, not array_filter(). > Actually, array_udelete is far more similar to array_filter than it is array_walk. . . -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, I see why with new Criticism section in the wiki page. You've also misunderstood that array_udelete() is array_walk() variant, not array_filter(). This may be the good reason why we should have array_udelete :) Regards, -- Yasuo Ohgaki yohg...@ohgaki.net 2012/8/22 Yasuo Ohgaki : > 2012/8/22 Levi Morrison : >> On Tue, Aug 21, 2012 at 3:45 PM, Andrew Faulds wrote: >>> On 21/08/12 22:43, Levi Morrison wrote: There is a reason to have a callable provided: custom comparison. Other array functions solve this by providing a `u` alternative: `int array_udelete(&$array, $value, bool function($value, $key))` Let's not deviate from established array naming conventions. (Yasuo, I'm looking at you) Cheers, Levi Morrison >>> >>> Yeah, this looks like a good solution and we have the best of both worlds. >>> >>> We get int array_delete(&$array, $value, $strict=TRUE); and int >>> array_udelete(&$array, $value, $callback=bool function ($value $key)); >>> >>> :) >>> >>> >> >> I'll still vote no on the RFC if it ever comes to it :) >> >> I'm only contributing here because I don't want pure madness to ever >> come to a vote when I'm absent and get voted in . . . > > Just curious why? > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Levi Morrison : > On Tue, Aug 21, 2012 at 3:45 PM, Andrew Faulds wrote: >> On 21/08/12 22:43, Levi Morrison wrote: >>> >>> There is a reason to have a callable provided: custom comparison. >>> Other array functions solve this by providing a `u` alternative: >>> >>> `int array_udelete(&$array, $value, bool function($value, $key))` >>> >>> Let's not deviate from established array naming conventions. (Yasuo, >>> I'm looking at you) >>> >>> Cheers, >>> >>> Levi Morrison >> >> Yeah, this looks like a good solution and we have the best of both worlds. >> >> We get int array_delete(&$array, $value, $strict=TRUE); and int >> array_udelete(&$array, $value, $callback=bool function ($value $key)); >> >> :) >> >> > > I'll still vote no on the RFC if it ever comes to it :) > > I'm only contributing here because I don't want pure madness to ever > come to a vote when I'm absent and get voted in . . . Just curious why? Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Tue, Aug 21, 2012 at 3:45 PM, Andrew Faulds wrote: > On 21/08/12 22:43, Levi Morrison wrote: >> >> There is a reason to have a callable provided: custom comparison. >> Other array functions solve this by providing a `u` alternative: >> >> `int array_udelete(&$array, $value, bool function($value, $key))` >> >> Let's not deviate from established array naming conventions. (Yasuo, >> I'm looking at you) >> >> Cheers, >> >> Levi Morrison > > Yeah, this looks like a good solution and we have the best of both worlds. > > We get int array_delete(&$array, $value, $strict=TRUE); and int > array_udelete(&$array, $value, $callback=bool function ($value $key)); > > :) > > I'll still vote no on the RFC if it ever comes to it :) I'm only contributing here because I don't want pure madness to ever come to a vote when I'm absent and get voted in . . . -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/22 Levi Morrison : > There is a reason to have a callable provided: custom comparison. > Other array functions solve this by providing a `u` alternative: > > `int array_udelete(&$array, $value, bool function($value, $key))` > > Let's not deviate from established array naming conventions. (Yasuo, > I'm looking at you) Good suggestion. Written to the wiki page. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 22:43, Levi Morrison wrote: There is a reason to have a callable provided: custom comparison. Other array functions solve this by providing a `u` alternative: `int array_udelete(&$array, $value, bool function($value, $key))` Let's not deviate from established array naming conventions. (Yasuo, I'm looking at you) Cheers, Levi Morrison Yeah, this looks like a good solution and we have the best of both worlds. We get int array_delete(&$array, $value, $strict=TRUE); and int array_udelete(&$array, $value, $callback=bool function ($value $key)); :) -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
There is a reason to have a callable provided: custom comparison. Other array functions solve this by providing a `u` alternative: `int array_udelete(&$array, $value, bool function($value, $key))` Let's not deviate from established array naming conventions. (Yasuo, I'm looking at you) Cheers, Levi Morrison -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 22:35, Yasuo Ohgaki wrote: 2012/8/22 Andrew Faulds : On 21/08/12 22:18, Yasuo Ohgaki wrote: 2012/8/22 Andrew Faulds : Er, so you're advocating adding another method to do the same thing? Why? Because novices don't know about array_walk(). I think I've written this over and over in this thread. So publicise array_walk() then. Don't add a new function. Already publicized more than a decade. IIRC, similar discussion was done years ago at least. I suppose it's time to add element deletion function based on values. If you don't understand how it could be useful, take a look at use cases of Ruby's delete_if. OK, but please don't subvert this. You want array_delete_if, I want array_delete. You want a functional method for deleting things. I want an atomic operation. Are we clear? Regards, -- Yasuo Ohgaki yohg...@ohgaki.net The whole point of this was to allow people to use arrays like sets, or easily remove list items. Not encourage people to use functional programming. Sure, people should use array_walk, but you've got to be kidding me if I you think I would honestly accept using this to remove array items by value: array_delete($array, function ($value) { return ($value == "that value"); }); I might as well use array_walk if we're going down this route. You seem to want to subvert the usefulness of this function and just provide an array_walk shorthand with less functionality. What I want is this: array_delete($array, "that value"); I do not want this ;) What's wrong with extensible way? It's for PHP 5.5, not PHP 4. But we have array_walk(). array_delete($array, function ($v) { return ($v == "that value"); }); We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. We may pass them as parameter, array_delete($array, "that value", "!=="); but it does not look a modern way to do and it is not extensible like with callable. No, it is a modern way. Modern and functional are not one and the same. Besides, how often we would like to delete elements based on element's value? I guess it's not so often for most people. Uh, I thought that was the whole point of this suggestion. You seem to want to subvert the original intentions (making it easier to remove list items and treat arrays as sets), to providing a new functional mechanism for removing lots of array items satisfying a criteria. Much more readable, does what you expect, and provides a significant, noticeable value over array_walk here. array_walk() is easy to use, IMHO. People just don't know array_walk() can be used to delete elements because of it's name. But adding a new function is NOT the solution. That is the job of documentation. That's like saying "people have no idea what strstr is, so let's make a new function with less functionality called string_position!". As I wrote in sample code, new array_delete is an intuitive name and convenient than array_walk. They are like array_pop/array_push and array_slice/array_splice to me. It's nothing like those. array_pop() and array_push() are simple, they take an array and an item to add. What's so terrible and evil and complex about making array_delete() remove an item? Why does it have to be functional and overcomplicated to do something we can already do, instead of providing a simple and convenient mechanism to remove an item by value? I do not understand this. Especially since, by your method, you should also provide a key since it provides no method to check item's key. Sorry, I just do not understand how your suggestion is useful. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net Regards, -- Yasuo Ohgaki yohg...@ohgaki.net As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Andrew Faulds : > On 21/08/12 22:18, Yasuo Ohgaki wrote: >> >> 2012/8/22 Andrew Faulds : >>> >>> Er, so you're advocating adding another method to do the same thing? Why? >> >> Because novices don't know about array_walk(). >> I think I've written this over and over in this thread. > > So publicise array_walk() then. Don't add a new function. Already publicized more than a decade. IIRC, similar discussion was done years ago at least. I suppose it's time to add element deletion function based on values. If you don't understand how it could be useful, take a look at use cases of Ruby's delete_if. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net > >>> The whole point of this was to allow people to use arrays like sets, or >>> easily remove list items. Not encourage people to use functional >>> programming. >>> >>> Sure, people should use array_walk, but you've got to be kidding me if I >>> you >>> think I would honestly accept using this to remove array items by value: >>> >>> array_delete($array, function ($value) { return ($value == "that value"); >>> }); >>> >>> I might as well use array_walk if we're going down this route. You seem >>> to >>> want to subvert the usefulness of this function and just provide an >>> array_walk shorthand with less functionality. >>> >>> What I want is this: >>> >>> array_delete($array, "that value"); >> >> I do not want this ;) >> What's wrong with extensible way? It's for PHP 5.5, not PHP 4. > > > But we have array_walk(). > >> array_delete($array, function ($v) { return ($v == "that value"); }); >> >> We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. >> We may pass them as parameter, >> >> array_delete($array, "that value", "!=="); >> >> but it does not look a modern way to do and it is not extensible >> like with callable. > > No, it is a modern way. Modern and functional are not one and the same. > >> >> Besides, how often we would like to delete elements based on >> element's value? I guess it's not so often for most people. > > Uh, I thought that was the whole point of this suggestion. You seem to want > to subvert the original intentions (making it easier to remove list items > and treat arrays as sets), to providing a new functional mechanism for > removing lots of array items satisfying a criteria. > >>> Much more readable, does what you expect, and provides a significant, >>> noticeable value over array_walk here. >> >> array_walk() is easy to use, IMHO. >> People just don't know array_walk() can be used to delete >> elements because of it's name. > > But adding a new function is NOT the solution. That is the job of > documentation. That's like saying "people have no idea what strstr is, so > let's make a new function with less functionality called string_position!". > >> >> As I wrote in sample code, new array_delete is an intuitive >> name and convenient than array_walk. They are like >> array_pop/array_push and array_slice/array_splice to me. > > It's nothing like those. array_pop() and array_push() are simple, they take > an array and an item to add. What's so terrible and evil and complex about > making array_delete() remove an item? Why does it have to be functional and > overcomplicated to do something we can already do, instead of providing a > simple and convenient mechanism to remove an item by value? > > I do not understand this. Especially since, by your method, you should also > provide a key since it provides no method to check item's key. > > Sorry, I just do not understand how your suggestion is useful. > >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net >> Regards, -- Yasuo Ohgaki yohg...@ohgaki.net >> As I mentioned earlier, array_walk() is the best way to delete >> elements >> with PHP >> more than a decade. It should be mentioned the Stack Overflow page, >> but it's not. >> >> It's just like adding >> array_pop()/array_push()/array_shift()/array_unshift() while >> we have array_slice()/array_splice(). >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net > > > > -- > Andrew Faulds > http://ajf.me/ > >>> >>> -- >>> Andrew Faulds >>> http://ajf.me/ >>> > > > -- > Andrew Faulds > http://ajf.me/ > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 22:18, Yasuo Ohgaki wrote: 2012/8/22 Andrew Faulds : Er, so you're advocating adding another method to do the same thing? Why? Because novices don't know about array_walk(). I think I've written this over and over in this thread. So publicise array_walk() then. Don't add a new function. The whole point of this was to allow people to use arrays like sets, or easily remove list items. Not encourage people to use functional programming. Sure, people should use array_walk, but you've got to be kidding me if I you think I would honestly accept using this to remove array items by value: array_delete($array, function ($value) { return ($value == "that value"); }); I might as well use array_walk if we're going down this route. You seem to want to subvert the usefulness of this function and just provide an array_walk shorthand with less functionality. What I want is this: array_delete($array, "that value"); I do not want this ;) What's wrong with extensible way? It's for PHP 5.5, not PHP 4. But we have array_walk(). array_delete($array, function ($v) { return ($v == "that value"); }); We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. We may pass them as parameter, array_delete($array, "that value", "!=="); but it does not look a modern way to do and it is not extensible like with callable. No, it is a modern way. Modern and functional are not one and the same. Besides, how often we would like to delete elements based on element's value? I guess it's not so often for most people. Uh, I thought that was the whole point of this suggestion. You seem to want to subvert the original intentions (making it easier to remove list items and treat arrays as sets), to providing a new functional mechanism for removing lots of array items satisfying a criteria. Much more readable, does what you expect, and provides a significant, noticeable value over array_walk here. array_walk() is easy to use, IMHO. People just don't know array_walk() can be used to delete elements because of it's name. But adding a new function is NOT the solution. That is the job of documentation. That's like saying "people have no idea what strstr is, so let's make a new function with less functionality called string_position!". As I wrote in sample code, new array_delete is an intuitive name and convenient than array_walk. They are like array_pop/array_push and array_slice/array_splice to me. It's nothing like those. array_pop() and array_push() are simple, they take an array and an item to add. What's so terrible and evil and complex about making array_delete() remove an item? Why does it have to be functional and overcomplicated to do something we can already do, instead of providing a simple and convenient mechanism to remove an item by value? I do not understand this. Especially since, by your method, you should also provide a key since it provides no method to check item's key. Sorry, I just do not understand how your suggestion is useful. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net Regards, -- Yasuo Ohgaki yohg...@ohgaki.net As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Andrew Faulds : > Er, so you're advocating adding another method to do the same thing? Why? Because novices don't know about array_walk(). I think I've written this over and over in this thread. > The whole point of this was to allow people to use arrays like sets, or > easily remove list items. Not encourage people to use functional > programming. > > Sure, people should use array_walk, but you've got to be kidding me if I you > think I would honestly accept using this to remove array items by value: > > array_delete($array, function ($value) { return ($value == "that value"); > }); > > I might as well use array_walk if we're going down this route. You seem to > want to subvert the usefulness of this function and just provide an > array_walk shorthand with less functionality. > > What I want is this: > > array_delete($array, "that value"); I do not want this ;) What's wrong with extensible way? It's for PHP 5.5, not PHP 4. array_delete($array, function ($v) { return ($v == "that value"); }); We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. We may pass them as parameter, array_delete($array, "that value", "!=="); but it does not look a modern way to do and it is not extensible like with callable. Besides, how often we would like to delete elements based on element's value? I guess it's not so often for most people. > Much more readable, does what you expect, and provides a significant, > noticeable value over array_walk here. array_walk() is easy to use, IMHO. People just don't know array_walk() can be used to delete elements because of it's name. As I wrote in sample code, new array_delete is an intuitive name and convenient than array_walk. They are like array_pop/array_push and array_slice/array_splice to me. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net > >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net >> >> As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net >>> >>> >>> >>> -- >>> Andrew Faulds >>> http://ajf.me/ >>> > > > -- > Andrew Faulds > http://ajf.me/ > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 21:32, Yasuo Ohgaki wrote: 2012/8/22 Andrew Faulds : On 21/08/12 21:00, Yasuo Ohgaki wrote: Hi 2012/8/22 Andrew Faulds : On 21/08/12 10:36, Yasuo Ohgaki wrote: Int would be better and callable should be accepted like array_walk(). It's better to have array_delete_recursive(), too. I updated the page. Callable? What? This is to remove a single value, like a set. If you want to remove based on a function, array_walk() is always available. And allowing a callable would prevent you from removing closures or strings! D: Original proposal was to delete all value that matches. It's not delete a single value. Treats it like a set, removes all but in practice only one will go if properly formed set. We could choose to remove only 1st element, but is it useful? People may do while (array_delete($array, "do not needed")); This is stupid O(n^2) code. OK. array_add() needs more discussion. What we should do with array value, accept callable or not, etc. Why accept a callable? I don't think it needs more discussion, I can't see how it could be made any better than it currently is. What's the point of adding NEW feature with less extensible against competitor? Take a look at Ruby's delete_if() With callable, one could do $array = [1,2,3,4,5,6,7,8]; $cnt = array_delete($array, function($v) { if ($v <== 4) return true; }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] Yes, but you seem to be ignoring me. I don't want that, because then I can't remove items a set containing strings or other callables, using this function. All element value and key are passed to function, you may remove any type of data if array_delete() accepts only callable. That's the reason why I suggest to accept callable only. Users should get used to closure/functional programming anyway. Yes, but I think this completely destroys the convenience of it. You might as well just use array_walk if it only supports callable. And array_walk is fine. array_delete should remove a value, not values according to a condition. We already have array_walk() and array_filter(). With array_walk() $array = [1,2,3,4,5,6,7,8]; $cnt = 0; array_walk($array, function($v) use (&$array, &$cnt) { if ($v <== 4) {$cnt++; return true;) }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] Oops, it should unset(). $array = [1,2,3,4,5,6,7,8]; $cnt = 0; array_walk($array, function($v, $k) use (&$array, &$cnt) { if ($v <== 4) {$cnt++; unset($array[$k];} }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] The problem is "Many PHP users do not know the best way to delete elements, while there is array_walk() for a long long time.", isn't it? Providing an intuitive and easier API for basic operation should be the solution, not providing simple method. Er, so you're advocating adding another method to do the same thing? Why? The whole point of this was to allow people to use arrays like sets, or easily remove list items. Not encourage people to use functional programming. Sure, people should use array_walk, but you've got to be kidding me if I you think I would honestly accept using this to remove array items by value: array_delete($array, function ($value) { return ($value == "that value"); }); I might as well use array_walk if we're going down this route. You seem to want to subvert the usefulness of this function and just provide an array_walk shorthand with less functionality. What I want is this: array_delete($array, "that value"); Much more readable, does what you expect, and provides a significant, noticeable value over array_walk here. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- Andrew Faulds http://ajf.me/ -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/22 Andrew Faulds : > On 21/08/12 21:00, Yasuo Ohgaki wrote: >> >> Hi >> >> 2012/8/22 Andrew Faulds : >>> >>> On 21/08/12 10:36, Yasuo Ohgaki wrote: Int would be better and callable should be accepted like array_walk(). It's better to have array_delete_recursive(), too. I updated the page. >>> >>> Callable? What? This is to remove a single value, like a set. If you want >>> to >>> remove based on a function, array_walk() is always available. And >>> allowing a >>> callable would prevent you from removing closures or strings! D: >> >> Original proposal was to delete all value that matches. >> It's not delete a single value. > > Treats it like a set, removes all but in practice only one will go if > properly formed set. > >> We could choose to remove only 1st element, but is it useful? >> People may do >> >> while (array_delete($array, "do not needed")); >> >> This is stupid O(n^2) code. > > OK. > >> array_add() needs more discussion. What we should do with array value, accept callable or not, etc. >>> >>> Why accept a callable? >>> I don't think it needs more discussion, I can't see how it could be made >>> any >>> better than it currently is. >> >> What's the point of adding NEW feature with less extensible against >> competitor? >> Take a look at Ruby's delete_if() >> >> With callable, one could do >> >> $array = [1,2,3,4,5,6,7,8]; >> $cnt = array_delete($array, function($v) { if ($v <== 4) return true; }); >> var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] > > Yes, but you seem to be ignoring me. I don't want that, because then I can't > remove items a set containing strings or other callables, using this > function. All element value and key are passed to function, you may remove any type of data if array_delete() accepts only callable. That's the reason why I suggest to accept callable only. Users should get used to closure/functional programming anyway. > > We already have array_walk() and array_filter(). > >> With array_walk() >> >> $array = [1,2,3,4,5,6,7,8]; >> $cnt = 0; >> array_walk($array, function($v) use (&$array, &$cnt) { if ($v <== 4) >> {$cnt++; return true;) }); >> var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] Oops, it should unset(). $array = [1,2,3,4,5,6,7,8]; $cnt = 0; array_walk($array, function($v, $k) use (&$array, &$cnt) { if ($v <== 4) {$cnt++; unset($array[$k];} }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] The problem is "Many PHP users do not know the best way to delete elements, while there is array_walk() for a long long time.", isn't it? Providing an intuitive and easier API for basic operation should be the solution, not providing simple method. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net >> >> As I mentioned earlier, array_walk() is the best way to delete elements >> with PHP >> more than a decade. It should be mentioned the Stack Overflow page, >> but it's not. >> >> It's just like adding >> array_pop()/array_push()/array_shift()/array_unshift() while >> we have array_slice()/array_splice(). >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net > > > > -- > Andrew Faulds > http://ajf.me/ > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 21:00, Yasuo Ohgaki wrote: Hi 2012/8/22 Andrew Faulds : On 21/08/12 10:36, Yasuo Ohgaki wrote: Int would be better and callable should be accepted like array_walk(). It's better to have array_delete_recursive(), too. I updated the page. Callable? What? This is to remove a single value, like a set. If you want to remove based on a function, array_walk() is always available. And allowing a callable would prevent you from removing closures or strings! D: Original proposal was to delete all value that matches. It's not delete a single value. Treats it like a set, removes all but in practice only one will go if properly formed set. We could choose to remove only 1st element, but is it useful? People may do while (array_delete($array, "do not needed")); This is stupid O(n^2) code. OK. array_add() needs more discussion. What we should do with array value, accept callable or not, etc. Why accept a callable? I don't think it needs more discussion, I can't see how it could be made any better than it currently is. What's the point of adding NEW feature with less extensible against competitor? Take a look at Ruby's delete_if() With callable, one could do $array = [1,2,3,4,5,6,7,8]; $cnt = array_delete($array, function($v) { if ($v <== 4) return true; }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] Yes, but you seem to be ignoring me. I don't want that, because then I can't remove items a set containing strings or other callables, using this function. We already have array_walk() and array_filter(). With array_walk() $array = [1,2,3,4,5,6,7,8]; $cnt = 0; array_walk($array, function($v) use (&$array, &$cnt) { if ($v <== 4) {$cnt++; return true;) }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi 2012/8/22 Andrew Faulds : > On 21/08/12 10:36, Yasuo Ohgaki wrote: >> >> Int would be better and callable should be accepted like array_walk(). >> It's better to have array_delete_recursive(), too. >> I updated the page. > > Callable? What? This is to remove a single value, like a set. If you want to > remove based on a function, array_walk() is always available. And allowing a > callable would prevent you from removing closures or strings! D: Original proposal was to delete all value that matches. It's not delete a single value. We could choose to remove only 1st element, but is it useful? People may do while (array_delete($array, "do not needed")); This is stupid O(n^2) code. > >> >> array_add() needs more discussion. >> What we should do with array value, accept callable or not, etc. > > Why accept a callable? > I don't think it needs more discussion, I can't see how it could be made any > better than it currently is. What's the point of adding NEW feature with less extensible against competitor? Take a look at Ruby's delete_if() With callable, one could do $array = [1,2,3,4,5,6,7,8]; $cnt = array_delete($array, function($v) { if ($v <== 4) return true; }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] With array_walk() $array = [1,2,3,4,5,6,7,8]; $cnt = 0; array_walk($array, function($v) use (&$array, &$cnt) { if ($v <== 4) {$cnt++; return true;) }); var_dump($cnt, $array); // $cnt = 4, $array = [5,6,7,8] As I mentioned earlier, array_walk() is the best way to delete elements with PHP more than a decade. It should be mentioned the Stack Overflow page, but it's not. It's just like adding array_pop()/array_push()/array_shift()/array_unshift() while we have array_slice()/array_splice(). Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 21/08/12 10:36, Yasuo Ohgaki wrote: Hi 2012/8/21 Tjerk Anne Meesters : On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: Thank you, but this isn't really anything like what I had in mind. What I had in mind is more like set-semantics for arrays, e.g. designed to work with sets of distinct values/objects. Since I do not have permission to write on the wiki, I posted an initial draft here: https://gist.github.com/321ad9b4b8c4e1713488 Just an idea, since array_delete() may remove multiple values, I would change the return value to (int) and return how many elements were removed from the array. Int would be better and callable should be accepted like array_walk(). It's better to have array_delete_recursive(), too. I updated the page. Callable? What? This is to remove a single value, like a set. If you want to remove based on a function, array_walk() is always available. And allowing a callable would prevent you from removing closures or strings! D: array_add() needs more discussion. What we should do with array value, accept callable or not, etc. Why accept a callable? I don't think it needs more discussion, I can't see how it could be made any better than it currently is. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net On Mon, Aug 20, 2012 at 10:10 PM, Yasuo Ohgaki wrote: Hi, 2012/8/21 Rasmus Schultz : I have a login (mindplay) but I do not have permission to post or edit anything on the wiki... I've created RFC for this https://wiki.php.net/rfc/array_delete Get wiki account and finish discussion. I may write patch for this with my spare time, but it may take while to find time. I suggest write patch and send pull request. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: Please let this die until someone is serious enough to come up with an rfc. This has been nothing but counterproductive arguing. If someone feels strongly about it, write an rfc then we can discuss? On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: Hi, 2012/8/21 Herman Radtke : May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals. I guess you haven't read later post. You've also made a novice mistake. array_filter() DO NOT delete elements, but creates new array. array_delete() is another form of array_walk(), not array_filter(). See my posts. Having a API for dedicated task is good thing. Who would argue array_pop()/array_push() isn't needed? Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php -- -- Tjerk -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi 2012/8/22 Levi Morrison : > On Tue, Aug 21, 2012 at 12:53 PM, Yasuo Ohgaki wrote: >> 2012/8/21 Levi Morrison : >>> >>> I'm against this RFC, but if you are going to even try to add >>> something, please keep it consistent! Don't modify `array_delete` to >>> take a callable, instead make a different function `array_udelete` or >>> something. >>> >> >> Original proposal is adding array_delete() and this is under discussion. >> We don't have to add array_add() >> >>> And keep default $strict values consistent with existing functions >>> that have that parameter. >> >> Users should use array_walk() when they would like to delete element(s). >> To be consistent, it should be callable. >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net > > I didn't say anything about `array_add`. I meant to say if you are > going to try to add something to the core that you need to be > consistent with the other array functions. > > Why use `array_walk` to delete elements? Isn't the whole point of > `array_delete` to make that process easier? > The reason why use array_walk is this is the best way to delete elements with PHP. >From the Stack Overflow's page (and this thread), we can tell the problem is lack of intuitive API for array element deletion. > I think you missed the whole point of my last message: keep the > functions you propose similar to ones that already exist. That's my point, too. array_walk() is there from PHP3 at least, IIRC. array_delete() is easier to use, too. i.e. No "use (&$array)" for closure and counter variable when user would like to know how many elements were deleted. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Tue, Aug 21, 2012 at 12:53 PM, Yasuo Ohgaki wrote: > 2012/8/21 Levi Morrison : >> >> I'm against this RFC, but if you are going to even try to add >> something, please keep it consistent! Don't modify `array_delete` to >> take a callable, instead make a different function `array_udelete` or >> something. >> > > Original proposal is adding array_delete() and this is under discussion. > We don't have to add array_add() > >> And keep default $strict values consistent with existing functions >> that have that parameter. > > Users should use array_walk() when they would like to delete element(s). > To be consistent, it should be callable. > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net I didn't say anything about `array_add`. I meant to say if you are going to try to add something to the core that you need to be consistent with the other array functions. Why use `array_walk` to delete elements? Isn't the whole point of `array_delete` to make that process easier? I think you missed the whole point of my last message: keep the functions you propose similar to ones that already exist. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/21 Levi Morrison : > On Tue, Aug 21, 2012 at 3:36 AM, Yasuo Ohgaki wrote: >> Hi >> >> 2012/8/21 Tjerk Anne Meesters : >>> On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: >>> Thank you, but this isn't really anything like what I had in mind. What I had in mind is more like set-semantics for arrays, e.g. designed to work with sets of distinct values/objects. Since I do not have permission to write on the wiki, I posted an initial draft here: https://gist.github.com/321ad9b4b8c4e1713488 >>> >>> >>> Just an idea, since array_delete() may remove multiple values, I would >>> change the return value to (int) and return how many elements were removed >>> from the array. >> >> Int would be better and callable should be accepted like array_walk(). >> It's better to have array_delete_recursive(), too. >> I updated the page. >> >> array_add() needs more discussion. >> What we should do with array value, accept callable or not, etc. >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net >> > > I'm against this RFC, but if you are going to even try to add > something, please keep it consistent! Don't modify `array_delete` to > take a callable, instead make a different function `array_udelete` or > something. > Original proposal is adding array_delete() and this is under discussion. We don't have to add array_add() > And keep default $strict values consistent with existing functions > that have that parameter. Users should use array_walk() when they would like to delete element(s). To be consistent, it should be callable. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Tue, Aug 21, 2012 at 3:36 AM, Yasuo Ohgaki wrote: > Hi > > 2012/8/21 Tjerk Anne Meesters : >> On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: >> >>> Thank you, but this isn't really anything like what I had in mind. >>> >>> What I had in mind is more like set-semantics for arrays, e.g. designed to >>> work with sets of distinct values/objects. >>> >>> Since I do not have permission to write on the wiki, I posted an initial >>> draft here: >>> >>> https://gist.github.com/321ad9b4b8c4e1713488 >> >> >> Just an idea, since array_delete() may remove multiple values, I would >> change the return value to (int) and return how many elements were removed >> from the array. > > Int would be better and callable should be accepted like array_walk(). > It's better to have array_delete_recursive(), too. > I updated the page. > > array_add() needs more discussion. > What we should do with array value, accept callable or not, etc. > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net > I'm against this RFC, but if you are going to even try to add something, please keep it consistent! Don't modify `array_delete` to take a callable, instead make a different function `array_udelete` or something. And keep default $strict values consistent with existing functions that have that parameter. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Hi 2012/8/21 Tjerk Anne Meesters : > On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: > >> Thank you, but this isn't really anything like what I had in mind. >> >> What I had in mind is more like set-semantics for arrays, e.g. designed to >> work with sets of distinct values/objects. >> >> Since I do not have permission to write on the wiki, I posted an initial >> draft here: >> >> https://gist.github.com/321ad9b4b8c4e1713488 > > > Just an idea, since array_delete() may remove multiple values, I would > change the return value to (int) and return how many elements were removed > from the array. Int would be better and callable should be accepted like array_walk(). It's better to have array_delete_recursive(), too. I updated the page. array_add() needs more discussion. What we should do with array value, accept callable or not, etc. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net > > >> >> >> >> On Mon, Aug 20, 2012 at 10:10 PM, Yasuo Ohgaki wrote: >> >> > Hi, >> > >> > 2012/8/21 Rasmus Schultz : >> > > I have a login (mindplay) but I do not have permission to post or edit >> > > anything on the wiki... >> > >> > I've created RFC for this >> > >> > https://wiki.php.net/rfc/array_delete >> > >> > Get wiki account and finish discussion. >> > I may write patch for this with my spare time, but >> > it may take while to find time. I suggest write patch >> > and send pull request. >> > >> > Regards, >> > >> > -- >> > Yasuo Ohgaki >> > yohg...@ohgaki.net >> > >> > > >> > > On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: >> > > >> > >> Please let this die until someone is serious enough to come up with an >> > >> rfc. This has been nothing but counterproductive arguing. If someone >> > feels >> > >> strongly about it, write an rfc then we can discuss? >> > >> On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: >> > >> >> > >>> Hi, >> > >>> >> > >>> 2012/8/21 Herman Radtke : >> > >>> >>> May be we should have something like >> > >>> >> >> > >>> >> >> >> > >>> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) >> > >>> return >> > >>> >> >> true; }) >> > >>> >> > >> > >>> >> > So array_filter? >> > >>> >> >> > >>> >> I'll use it or like for deleting, but the point of this thread is >> > >>> >> "intuitive function for deleting element(s)" >> > >>> >> >> > >>> >> array_delete($array, $value|callable) >> > >>> >> >> > >>> >> would be nicer for users, perhaps. >> > >>> > >> > >>> > >> > >>> > You are basically asking to alias array_filter with "array_delete". >> > >>> That is >> > >>> > a very slippery slope. I think array_filter is very a very obvious >> > >>> choice to >> > >>> > remove something from an array. The "filter" function/method is >> > common >> > >>> in >> > >>> > functional languages (and functional frameworks like Underscore). >> > >>> > >> > >>> > These are things developers just need to learn as part of >> > development. >> > >>> > Really, this is entire thread should be on stack overflow, not >> > >>> internals. >> > >>> >> > >>> I guess you haven't read later post. >> > >>> >> > >>> You've also made a novice mistake. >> > >>> array_filter() DO NOT delete elements, but creates new array. >> > >>> array_delete() is another form of array_walk(), not array_filter(). >> > >>> See my posts. >> > >>> >> > >>> Having a API for dedicated task is good thing. >> > >>> Who would argue array_pop()/array_push() isn't needed? >> > >>> >> > >>> Regards, >> > >>> >> > >>> -- >> > >>> Yasuo Ohgaki >> > >>> yohg...@ohgaki.net >> > >>> >> > >>> -- >> > >>> PHP Internals - PHP Runtime Development Mailing List >> > >>> To unsubscribe, visit: http://www.php.net/unsub.php >> > >>> >> > >>> >> > >> > > > > -- > -- > Tjerk -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Tue, Aug 21, 2012 at 10:31 AM, Rasmus Schultz wrote: > Thank you, but this isn't really anything like what I had in mind. > > What I had in mind is more like set-semantics for arrays, e.g. designed to > work with sets of distinct values/objects. > > Since I do not have permission to write on the wiki, I posted an initial > draft here: > > https://gist.github.com/321ad9b4b8c4e1713488 Just an idea, since array_delete() may remove multiple values, I would change the return value to (int) and return how many elements were removed from the array. > > > > On Mon, Aug 20, 2012 at 10:10 PM, Yasuo Ohgaki wrote: > > > Hi, > > > > 2012/8/21 Rasmus Schultz : > > > I have a login (mindplay) but I do not have permission to post or edit > > > anything on the wiki... > > > > I've created RFC for this > > > > https://wiki.php.net/rfc/array_delete > > > > Get wiki account and finish discussion. > > I may write patch for this with my spare time, but > > it may take while to find time. I suggest write patch > > and send pull request. > > > > Regards, > > > > -- > > Yasuo Ohgaki > > yohg...@ohgaki.net > > > > > > > > On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: > > > > > >> Please let this die until someone is serious enough to come up with an > > >> rfc. This has been nothing but counterproductive arguing. If someone > > feels > > >> strongly about it, write an rfc then we can discuss? > > >> On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: > > >> > > >>> Hi, > > >>> > > >>> 2012/8/21 Herman Radtke : > > >>> >>> May be we should have something like > > >>> >> > > >>> >> >> > > >>> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) > > >>> return > > >>> >> >> true; }) > > >>> >> > > > >>> >> > So array_filter? > > >>> >> > > >>> >> I'll use it or like for deleting, but the point of this thread is > > >>> >> "intuitive function for deleting element(s)" > > >>> >> > > >>> >> array_delete($array, $value|callable) > > >>> >> > > >>> >> would be nicer for users, perhaps. > > >>> > > > >>> > > > >>> > You are basically asking to alias array_filter with "array_delete". > > >>> That is > > >>> > a very slippery slope. I think array_filter is very a very obvious > > >>> choice to > > >>> > remove something from an array. The "filter" function/method is > > common > > >>> in > > >>> > functional languages (and functional frameworks like Underscore). > > >>> > > > >>> > These are things developers just need to learn as part of > > development. > > >>> > Really, this is entire thread should be on stack overflow, not > > >>> internals. > > >>> > > >>> I guess you haven't read later post. > > >>> > > >>> You've also made a novice mistake. > > >>> array_filter() DO NOT delete elements, but creates new array. > > >>> array_delete() is another form of array_walk(), not array_filter(). > > >>> See my posts. > > >>> > > >>> Having a API for dedicated task is good thing. > > >>> Who would argue array_pop()/array_push() isn't needed? > > >>> > > >>> Regards, > > >>> > > >>> -- > > >>> Yasuo Ohgaki > > >>> yohg...@ohgaki.net > > >>> > > >>> -- > > >>> PHP Internals - PHP Runtime Development Mailing List > > >>> To unsubscribe, visit: http://www.php.net/unsub.php > > >>> > > >>> > > > -- -- Tjerk
Re: [PHP-DEV] re: removing an item from an array
On Mon, Aug 20, 2012 at 8:47 PM, Levi Morrison wrote: > On Mon, Aug 20, 2012 at 8:31 PM, Rasmus Schultz wrote: >> Thank you, but this isn't really anything like what I had in mind. >> >> What I had in mind is more like set-semantics for arrays, e.g. designed to >> work with sets of distinct values/objects. >> >> Since I do not have permission to write on the wiki, I posted an initial >> draft here: >> >> https://gist.github.com/321ad9b4b8c4e1713488 >> >> > > I'll update the RFC with your information, Rasmus. Done. I suggest that you start a new emaili thread based on the RFC when you feel the RFC is ready. If you have not already, you should ask for wiki karma (see https://wiki.php.net/rfc/array_delete?do=register). -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Mon, Aug 20, 2012 at 8:31 PM, Rasmus Schultz wrote: > Thank you, but this isn't really anything like what I had in mind. > > What I had in mind is more like set-semantics for arrays, e.g. designed to > work with sets of distinct values/objects. > > Since I do not have permission to write on the wiki, I posted an initial > draft here: > > https://gist.github.com/321ad9b4b8c4e1713488 > > I'll update the RFC with your information, Rasmus. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Thank you, but this isn't really anything like what I had in mind. What I had in mind is more like set-semantics for arrays, e.g. designed to work with sets of distinct values/objects. Since I do not have permission to write on the wiki, I posted an initial draft here: https://gist.github.com/321ad9b4b8c4e1713488 On Mon, Aug 20, 2012 at 10:10 PM, Yasuo Ohgaki wrote: > Hi, > > 2012/8/21 Rasmus Schultz : > > I have a login (mindplay) but I do not have permission to post or edit > > anything on the wiki... > > I've created RFC for this > > https://wiki.php.net/rfc/array_delete > > Get wiki account and finish discussion. > I may write patch for this with my spare time, but > it may take while to find time. I suggest write patch > and send pull request. > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net > > > > > On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: > > > >> Please let this die until someone is serious enough to come up with an > >> rfc. This has been nothing but counterproductive arguing. If someone > feels > >> strongly about it, write an rfc then we can discuss? > >> On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: > >> > >>> Hi, > >>> > >>> 2012/8/21 Herman Radtke : > >>> >>> May be we should have something like > >>> >> > >>> >> >> > >>> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) > >>> return > >>> >> >> true; }) > >>> >> > > >>> >> > So array_filter? > >>> >> > >>> >> I'll use it or like for deleting, but the point of this thread is > >>> >> "intuitive function for deleting element(s)" > >>> >> > >>> >> array_delete($array, $value|callable) > >>> >> > >>> >> would be nicer for users, perhaps. > >>> > > >>> > > >>> > You are basically asking to alias array_filter with "array_delete". > >>> That is > >>> > a very slippery slope. I think array_filter is very a very obvious > >>> choice to > >>> > remove something from an array. The "filter" function/method is > common > >>> in > >>> > functional languages (and functional frameworks like Underscore). > >>> > > >>> > These are things developers just need to learn as part of > development. > >>> > Really, this is entire thread should be on stack overflow, not > >>> internals. > >>> > >>> I guess you haven't read later post. > >>> > >>> You've also made a novice mistake. > >>> array_filter() DO NOT delete elements, but creates new array. > >>> array_delete() is another form of array_walk(), not array_filter(). > >>> See my posts. > >>> > >>> Having a API for dedicated task is good thing. > >>> Who would argue array_pop()/array_push() isn't needed? > >>> > >>> Regards, > >>> > >>> -- > >>> Yasuo Ohgaki > >>> yohg...@ohgaki.net > >>> > >>> -- > >>> PHP Internals - PHP Runtime Development Mailing List > >>> To unsubscribe, visit: http://www.php.net/unsub.php > >>> > >>> >
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/21 Rasmus Schultz : > I have a login (mindplay) but I do not have permission to post or edit > anything on the wiki... I've created RFC for this https://wiki.php.net/rfc/array_delete Get wiki account and finish discussion. I may write patch for this with my spare time, but it may take while to find time. I suggest write patch and send pull request. Regards, -- Yasuo Ohgaki yohg...@ohgaki.net > > On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: > >> Please let this die until someone is serious enough to come up with an >> rfc. This has been nothing but counterproductive arguing. If someone feels >> strongly about it, write an rfc then we can discuss? >> On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: >> >>> Hi, >>> >>> 2012/8/21 Herman Radtke : >>> >>> May be we should have something like >>> >> >>> >> >> >>> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) >>> return >>> >> >> true; }) >>> >> > >>> >> > So array_filter? >>> >> >>> >> I'll use it or like for deleting, but the point of this thread is >>> >> "intuitive function for deleting element(s)" >>> >> >>> >> array_delete($array, $value|callable) >>> >> >>> >> would be nicer for users, perhaps. >>> > >>> > >>> > You are basically asking to alias array_filter with "array_delete". >>> That is >>> > a very slippery slope. I think array_filter is very a very obvious >>> choice to >>> > remove something from an array. The "filter" function/method is common >>> in >>> > functional languages (and functional frameworks like Underscore). >>> > >>> > These are things developers just need to learn as part of development. >>> > Really, this is entire thread should be on stack overflow, not >>> internals. >>> >>> I guess you haven't read later post. >>> >>> You've also made a novice mistake. >>> array_filter() DO NOT delete elements, but creates new array. >>> array_delete() is another form of array_walk(), not array_filter(). >>> See my posts. >>> >>> Having a API for dedicated task is good thing. >>> Who would argue array_pop()/array_push() isn't needed? >>> >>> Regards, >>> >>> -- >>> Yasuo Ohgaki >>> yohg...@ohgaki.net >>> >>> -- >>> PHP Internals - PHP Runtime Development Mailing List >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
I have a login (mindplay) but I do not have permission to post or edit anything on the wiki... On Mon, Aug 20, 2012 at 8:01 PM, Will Fitch wrote: > Please let this die until someone is serious enough to come up with an > rfc. This has been nothing but counterproductive arguing. If someone feels > strongly about it, write an rfc then we can discuss? > On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: > >> Hi, >> >> 2012/8/21 Herman Radtke : >> >>> May be we should have something like >> >> >> >> >> >> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) >> return >> >> >> true; }) >> >> > >> >> > So array_filter? >> >> >> >> I'll use it or like for deleting, but the point of this thread is >> >> "intuitive function for deleting element(s)" >> >> >> >> array_delete($array, $value|callable) >> >> >> >> would be nicer for users, perhaps. >> > >> > >> > You are basically asking to alias array_filter with "array_delete". >> That is >> > a very slippery slope. I think array_filter is very a very obvious >> choice to >> > remove something from an array. The "filter" function/method is common >> in >> > functional languages (and functional frameworks like Underscore). >> > >> > These are things developers just need to learn as part of development. >> > Really, this is entire thread should be on stack overflow, not >> internals. >> >> I guess you haven't read later post. >> >> You've also made a novice mistake. >> array_filter() DO NOT delete elements, but creates new array. >> array_delete() is another form of array_walk(), not array_filter(). >> See my posts. >> >> Having a API for dedicated task is good thing. >> Who would argue array_pop()/array_push() isn't needed? >> >> Regards, >> >> -- >> Yasuo Ohgaki >> yohg...@ohgaki.net >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> >>
Re: [PHP-DEV] re: removing an item from an array
Please let this die until someone is serious enough to come up with an rfc. This has been nothing but counterproductive arguing. If someone feels strongly about it, write an rfc then we can discuss? On Aug 20, 2012 7:53 PM, "Yasuo Ohgaki" wrote: > Hi, > > 2012/8/21 Herman Radtke : > >>> May be we should have something like > >> > >> >> > >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return > >> >> true; }) > >> > > >> > So array_filter? > >> > >> I'll use it or like for deleting, but the point of this thread is > >> "intuitive function for deleting element(s)" > >> > >> array_delete($array, $value|callable) > >> > >> would be nicer for users, perhaps. > > > > > > You are basically asking to alias array_filter with "array_delete". That > is > > a very slippery slope. I think array_filter is very a very obvious > choice to > > remove something from an array. The "filter" function/method is common in > > functional languages (and functional frameworks like Underscore). > > > > These are things developers just need to learn as part of development. > > Really, this is entire thread should be on stack overflow, not internals. > > I guess you haven't read later post. > > You've also made a novice mistake. > array_filter() DO NOT delete elements, but creates new array. > array_delete() is another form of array_walk(), not array_filter(). > See my posts. > > Having a API for dedicated task is good thing. > Who would argue array_pop()/array_push() isn't needed? > > Regards, > > -- > Yasuo Ohgaki > yohg...@ohgaki.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP-DEV] re: removing an item from an array
Hi, 2012/8/21 Herman Radtke : >>> May be we should have something like >> >> >> >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return >> >> true; }) >> > >> > So array_filter? >> >> I'll use it or like for deleting, but the point of this thread is >> "intuitive function for deleting element(s)" >> >> array_delete($array, $value|callable) >> >> would be nicer for users, perhaps. > > > You are basically asking to alias array_filter with "array_delete". That is > a very slippery slope. I think array_filter is very a very obvious choice to > remove something from an array. The "filter" function/method is common in > functional languages (and functional frameworks like Underscore). > > These are things developers just need to learn as part of development. > Really, this is entire thread should be on stack overflow, not internals. I guess you haven't read later post. You've also made a novice mistake. array_filter() DO NOT delete elements, but creates new array. array_delete() is another form of array_walk(), not array_filter(). See my posts. Having a API for dedicated task is good thing. Who would argue array_pop()/array_push() isn't needed? Regards, -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Also, `array_splice` will remove the index while modifying the array in-place. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 19:05, Levi Morrison wrote: Some major points to consider for `array_delete`'s behavior: 1. Should items be compared with `==`, `===`, or custom comparison? If we use `==` or `===` we'd probably add `array_udelete` to allow a custom comparator. array_delete($array, $value, $all=false, $strict=false) 2. Should it stop when it encounters the first value that matches? If it does, should we add a function that searches in the reverse direction? ^ 3. Should it modify the array in-place? If so, should we have another function that returns a copy of the array that does not include the removed value(s) instead? Modify in-place. No need for another, that's filter's job imo. If someone wants to go through and define all of these cases and propose a patch, more power to them. Might do so. - Here are some reasons that aren't related to the above as to why I'm against adding `array_delete`: 1. PHP arrays are not sets. PHP arrays are meant to be a list and an associative array. As such, a PHP array can act as any* data structure that can be built from a list or associative array. A data structure that removes something by value is typically associated with a set and therefore does not belong in an array. 2. Using other array functions cover this use case AND do a better job. Want to remove the first instance of the value? Use `array_search` to find the index and unset it. If you want to reorder the array you can use `array_search` to find the index and use `array_slice`. Want to remove all instances of the value in the array? Use `array_filter`. -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Some major points to consider for `array_delete`'s behavior: 1. Should items be compared with `==`, `===`, or custom comparison? If we use `==` or `===` we'd probably add `array_udelete` to allow a custom comparator. 2. Should it stop when it encounters the first value that matches? If it does, should we add a function that searches in the reverse direction? 3. Should it modify the array in-place? If so, should we have another function that returns a copy of the array that does not include the removed value(s) instead? If someone wants to go through and define all of these cases and propose a patch, more power to them. - Here are some reasons that aren't related to the above as to why I'm against adding `array_delete`: 1. PHP arrays are not sets. PHP arrays are meant to be a list and an associative array. As such, a PHP array can act as any* data structure that can be built from a list or associative array. A data structure that removes something by value is typically associated with a set and therefore does not belong in an array. 2. Using other array functions cover this use case AND do a better job. Want to remove the first instance of the value? Use `array_search` to find the index and unset it. If you want to reorder the array you can use `array_search` to find the index and use `array_slice`. Want to remove all instances of the value in the array? Use `array_filter`. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 18:43, Sebastian Krebs wrote: Am 20.08.2012 19:00, schrieb Andrew Faulds: On 20/08/12 17:47, Herman Radtke wrote: May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals. You seem a little arrogant. Arguably, a lot of array functions are unnecessary. But PHP is not supposed to be an extremely minimal language. Convenience functions are a good thing. We have array_pad for instance: completely unnecessary, you can do it manually with other array functions. Array_fill_keys and array_fill, too. array_flip is also unnecessary. Heck, who needs sorting, you can do that manually too. array_delete would be a more convenient, and more readable way to remove a value from an array. Yes, you can already remove array items, that's not the point. The point is this way is simpler and more convenient. So you just want a convenient and readable way and you realise yourself, that it is really simple to implement. So: Why don't you just implement it yourself? function array_delete($array, $value) { // Your code here } What I don't understand is, why should every function goes directly into the core, if you can achieve exactly the same without core changes? I'd rather not argue any further about this (let's make an RFC and vote). I've already addressed this point. Regards, Sebastian Also, as someone else mentioned, PHP's universal collection datatype is a great thing. It is an associative array, it is a list, it is a tuple, it is a set, it can be used in many ways, it's incredibly versatile. Adding array_delete would allow you to use it like a set more easily. Just my 2½¢ :) -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Am 20.08.2012 19:00, schrieb Andrew Faulds: On 20/08/12 17:47, Herman Radtke wrote: May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals. You seem a little arrogant. Arguably, a lot of array functions are unnecessary. But PHP is not supposed to be an extremely minimal language. Convenience functions are a good thing. We have array_pad for instance: completely unnecessary, you can do it manually with other array functions. Array_fill_keys and array_fill, too. array_flip is also unnecessary. Heck, who needs sorting, you can do that manually too. array_delete would be a more convenient, and more readable way to remove a value from an array. Yes, you can already remove array items, that's not the point. The point is this way is simpler and more convenient. So you just want a convenient and readable way and you realise yourself, that it is really simple to implement. So: Why don't you just implement it yourself? function array_delete($array, $value) { // Your code here } What I don't understand is, why should every function goes directly into the core, if you can achieve exactly the same without core changes? Regards, Sebastian Also, as someone else mentioned, PHP's universal collection datatype is a great thing. It is an associative array, it is a list, it is a tuple, it is a set, it can be used in many ways, it's incredibly versatile. Adding array_delete would allow you to use it like a set more easily. Just my 2½¢ :) -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 18:27, Levi Morrison wrote: You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). This about sums up my opinion on deleting things by value on a PHP array. ** Me and Levi had a private email back-and-forth about this. Like many things here, this discussion has become a pseudo-argument, and it's unclear whether people actually think it's a good idea or not. So let's make an RFC (I think array_delete($array, $value, $all=false), mirrors Python's replace-one-only by default), vote on it, and that can decide things. So we can avoid argument. Don't like the syntax? Vote against it, but I don't see how it could be much better. -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
> You are basically asking to alias array_filter with "array_delete". That is > a very slippery slope. I think array_filter is a very obvious choice > to remove something from an array. The "filter" function/method is common > in functional languages (and functional frameworks like Underscore). This about sums up my opinion on deleting things by value on a PHP array. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 18:11, Levi Morrison wrote: Adding array_delete would allow you to use it like a set more It's not a set and wasn't meant to be. If you want really bad set behavior, feel free to use an array as one. Arrays also aren't lists or associative arrays, strictly speaking. And there is another use case: removing of list items by value, instead of key. -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
> Adding array_delete would allow you to use it like a set more It's not a set and wasn't meant to be. If you want really bad set behavior, feel free to use an array as one. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 17:47, Herman Radtke wrote: May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals. You seem a little arrogant. Arguably, a lot of array functions are unnecessary. But PHP is not supposed to be an extremely minimal language. Convenience functions are a good thing. We have array_pad for instance: completely unnecessary, you can do it manually with other array functions. Array_fill_keys and array_fill, too. array_flip is also unnecessary. Heck, who needs sorting, you can do that manually too. array_delete would be a more convenient, and more readable way to remove a value from an array. Yes, you can already remove array items, that's not the point. The point is this way is simpler and more convenient. Also, as someone else mentioned, PHP's universal collection datatype is a great thing. It is an associative array, it is a list, it is a tuple, it is a set, it can be used in many ways, it's incredibly versatile. Adding array_delete would allow you to use it like a set more easily. Just my 2½¢ :) -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
>> May be we should have something like > >> > >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return > true; }) > > > > So array_filter? > > I'll use it or like for deleting, but the point of this thread is > "intuitive function for deleting element(s)" > > array_delete($array, $value|callable) > > would be nicer for users, perhaps. You are basically asking to alias array_filter with "array_delete". That is a very slippery slope. I think array_filter is very a very obvious choice to remove something from an array. The "filter" function/method is common in functional languages (and functional frameworks like Underscore). These are things developers just need to learn as part of development. Really, this is entire thread should be on stack overflow, not internals. -- Herman Radtke hermanrad...@gmail.com | http://hermanradtke.com
Re: [PHP-DEV] re: removing an item from an array
Absolutely, you're right. I have a tendency to get dragged into those. I apologize. On Fri, Aug 17, 2012 at 5:50 PM, Nikita Popov wrote: > > Could we please stop these pseudo-arguments?
Re: [PHP-DEV] re: removing an item from an array
2012/8/20 Andrew Faulds : > On 20/08/12 00:16, Yasuo Ohgaki wrote: >> >> 2012/8/20 Andrew Faulds : >>> >>> On 20/08/12 00:05, Yasuo Ohgaki wrote: 2012/8/20 Etienne Kneuss : > > On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki > wrote: >> >> 2012/8/18 Rasmus Lerdorf : >>> >>> On 08/17/2012 05:21 PM, Rasmus Schultz wrote: > > if(($key = array_search($del_val, $messages)) !== false) { > unset($messages[$key]); > } > > Nothing horrible here. > I disagree - this is (or should be) a simple, atomic operation... yet, you've got a function-call, an intermediary variable, a boolean test, and an unset statement repeating the name of the array you're deleting from. This should be a simple statement or function/method-call, and in most other languages it would be... >>> >>> Really? I can't think of a single language that has a call to remove >>> an >>> element by value in a key-value hash. Do you have some examples? What >>> do >>> you do with duplicates? >>> >> Ruby can do (using irb) >> >> ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} >>=> {"apple"=>150, "banana"=>300, "lemon"=>300} >> ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } >>=> {"apple"=>150} >> >> May be we should have something like >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return >> true; }) > > So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. >>> >>> A callable? Wouldn't that mean you couldn't delete strings? :( >> >> If you read my previous post, you'll see why it would be nicer with >> callable. > > Being unable to remove callables from an array would be very strange, and I > think for the use case you presented array_filter works fine. Of course it works. $array = array_filter($array, function($v) use ($del_val) { return ($v !== $del_val); }); It does not delete element(s), but creates new array. void array_delete ( array &$input [, callable $callback = "" | $values_to_be_deleted ] ) This will delete element(s). We can use array_walk() to delete element(s) from array also. php > $array = array(1,2,3,4,5); php > array_walk($array, function($val, $key) use (&$array) {if ($val == 3) unset($array[$key]);}); php > var_dump($array); array(4) { [0]=> int(1) [1]=> int(2) [3]=> int(4) [4]=> int(5) } I suppose this isn't an intuitive way for novices because stack overflow's answers didn't have this method that actually delete element(s) from an array. Adding an intuitive element deletion function is the point of this thread, isn't it? I'll vote +1 for adding array_delete(). Regards, -- Yasuo Ohgaki > >> Ruby can do (using irb) >> >> ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} >>=> {"apple"=>150, "banana"=>300, "lemon"=>300} >> ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } >>=> {"apple"=>150} >> >> May be we should have something like >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return >> true; }) >> >> -- >> Yasuo Ohgaki > > > > -- > Andrew Faulds > http://ajf.me/ > -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 00:16, Yasuo Ohgaki wrote: 2012/8/20 Andrew Faulds : On 20/08/12 00:05, Yasuo Ohgaki wrote: 2012/8/20 Etienne Kneuss : On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki wrote: 2012/8/18 Rasmus Lerdorf : On 08/17/2012 05:21 PM, Rasmus Schultz wrote: if(($key = array_search($del_val, $messages)) !== false) { unset($messages[$key]); } Nothing horrible here. I disagree - this is (or should be) a simple, atomic operation... yet, you've got a function-call, an intermediary variable, a boolean test, and an unset statement repeating the name of the array you're deleting from. This should be a simple statement or function/method-call, and in most other languages it would be... Really? I can't think of a single language that has a call to remove an element by value in a key-value hash. Do you have some examples? What do you do with duplicates? Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. A callable? Wouldn't that mean you couldn't delete strings? :( If you read my previous post, you'll see why it would be nicer with callable. Being unable to remove callables from an array would be very strange, and I think for the use case you presented array_filter works fine. Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) -- Yasuo Ohgaki -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/20 Andrew Faulds : > On 20/08/12 00:05, Yasuo Ohgaki wrote: >> >> 2012/8/20 Etienne Kneuss : >>> >>> On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki >>> wrote: 2012/8/18 Rasmus Lerdorf : > > On 08/17/2012 05:21 PM, Rasmus Schultz wrote: >>> >>> if(($key = array_search($del_val, $messages)) !== false) { >>> unset($messages[$key]); >>> } >>> >>> Nothing horrible here. >>> >> I disagree - this is (or should be) a simple, atomic operation... >> yet, you've got a function-call, an intermediary variable, a boolean >> test, >> and an unset statement repeating the name of the array you're deleting >> from. >> >> This should be a simple statement or function/method-call, and in most >> other languages it would be... > > Really? I can't think of a single language that has a call to remove an > element by value in a key-value hash. Do you have some examples? What > do > you do with duplicates? > Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) >>> >>> So array_filter? >> >> I'll use it or like for deleting, but the point of this thread is >> "intuitive function for deleting element(s)" >> >> array_delete($array, $value|callable) >> >> would be nicer for users, perhaps. > > A callable? Wouldn't that mean you couldn't delete strings? :( If you read my previous post, you'll see why it would be nicer with callable. Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) -- Yasuo Ohgaki -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 20/08/12 00:05, Yasuo Ohgaki wrote: 2012/8/20 Etienne Kneuss : On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki wrote: 2012/8/18 Rasmus Lerdorf : On 08/17/2012 05:21 PM, Rasmus Schultz wrote: if(($key = array_search($del_val, $messages)) !== false) { unset($messages[$key]); } Nothing horrible here. I disagree - this is (or should be) a simple, atomic operation... yet, you've got a function-call, an intermediary variable, a boolean test, and an unset statement repeating the name of the array you're deleting from. This should be a simple statement or function/method-call, and in most other languages it would be... Really? I can't think of a single language that has a call to remove an element by value in a key-value hash. Do you have some examples? What do you do with duplicates? Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. A callable? Wouldn't that mean you couldn't delete strings? :( -- Yasuo Ohgaki yohg...@ohgaki.net -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/20 Etienne Kneuss : > On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki wrote: >> 2012/8/18 Rasmus Lerdorf : >>> On 08/17/2012 05:21 PM, Rasmus Schultz wrote: > > if(($key = array_search($del_val, $messages)) !== false) { > unset($messages[$key]); > } > > Nothing horrible here. > I disagree - this is (or should be) a simple, atomic operation... yet, you've got a function-call, an intermediary variable, a boolean test, and an unset statement repeating the name of the array you're deleting from. This should be a simple statement or function/method-call, and in most other languages it would be... >>> >>> Really? I can't think of a single language that has a call to remove an >>> element by value in a key-value hash. Do you have some examples? What do >>> you do with duplicates? >>> >> >> Ruby can do (using irb) >> >> ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} >> => {"apple"=>150, "banana"=>300, "lemon"=>300} >> ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } >> => {"apple"=>150} >> >> May be we should have something like >> >> array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; >> }) > > So array_filter? I'll use it or like for deleting, but the point of this thread is "intuitive function for deleting element(s)" array_delete($array, $value|callable) would be nicer for users, perhaps. -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Sun, Aug 19, 2012 at 11:57 PM, Yasuo Ohgaki wrote: > 2012/8/18 Rasmus Lerdorf : >> On 08/17/2012 05:21 PM, Rasmus Schultz wrote: if(($key = array_search($del_val, $messages)) !== false) { unset($messages[$key]); } Nothing horrible here. >>> >>> I disagree - this is (or should be) a simple, atomic operation... >>> yet, you've got a function-call, an intermediary variable, a boolean test, >>> and an unset statement repeating the name of the array you're deleting from. >>> >>> This should be a simple statement or function/method-call, and in most >>> other languages it would be... >> >> Really? I can't think of a single language that has a call to remove an >> element by value in a key-value hash. Do you have some examples? What do >> you do with duplicates? >> > > Ruby can do (using irb) > > ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} > => {"apple"=>150, "banana"=>300, "lemon"=>300} > ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } > => {"apple"=>150} > > May be we should have something like > > array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) So array_filter? > > -- > Yasuo Ohgaki > yohg...@ohgaki.net > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > -- Etienne Kneuss http://www.colder.ch -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
2012/8/18 Rasmus Lerdorf : > On 08/17/2012 05:21 PM, Rasmus Schultz wrote: >>> >>> if(($key = array_search($del_val, $messages)) !== false) { >>> unset($messages[$key]); >>> } >>> >>> Nothing horrible here. >>> >> >> I disagree - this is (or should be) a simple, atomic operation... >> yet, you've got a function-call, an intermediary variable, a boolean test, >> and an unset statement repeating the name of the array you're deleting from. >> >> This should be a simple statement or function/method-call, and in most >> other languages it would be... > > Really? I can't think of a single language that has a call to remove an > element by value in a key-value hash. Do you have some examples? What do > you do with duplicates? > Ruby can do (using irb) ruby-1.9.2-p180 :007 > h = {"apple"=>150, "banana"=>300, "lemon"=>300} => {"apple"=>150, "banana"=>300, "lemon"=>300} ruby-1.9.2-p180 :008 > h.delete_if { |k,v| v==300 } => {"apple"=>150} May be we should have something like array_delete_if($array, function($v, $k=null) { if ($v == 300) return true; }) -- Yasuo Ohgaki yohg...@ohgaki.net -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 19/08/12 01:39, Morgan L. Owens wrote: On 2012-08-19 10:25, Andrew Faulds wrote: On 18/08/12 14:52, Morgan L. Owens wrote: How simple is it? Does it: 1) Remove one occurrence of the element (presumably the first) or all? 2) Reindex the array (as someone else argued was necessary to make it "properly indexed" afterwards) or not? 3) Modify the array in-place or return a modified array? 4) Use type-strict or normal comparisons? So to answer you, 1) one, 2), no, 3) in-place, 4) type-strict (I don't see how a weakly-typed comparison for identifying an array value would help anyone). So ... using a different definition of "value" than that used by array_search() and array_keys(), then? Assuming you mean the strictness of comparison, you could have an optional $strict parameter defaulting to false like array_search(). (and hence non-strict by default) -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 2012-08-19 10:25, Andrew Faulds wrote: On 18/08/12 14:52, Morgan L. Owens wrote: How simple is it? Does it: 1) Remove one occurrence of the element (presumably the first) or all? 2) Reindex the array (as someone else argued was necessary to make it "properly indexed" afterwards) or not? 3) Modify the array in-place or return a modified array? 4) Use type-strict or normal comparisons? So to answer you, 1) one, 2), no, 3) in-place, 4) type-strict (I don't see how a weakly-typed comparison for identifying an array value would help anyone). So ... using a different definition of "value" than that used by array_search() and array_keys(), then? -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 18/08/12 14:52, Morgan L. Owens wrote: Rasmus Schultz wrote: > I disagree - this is (or should be) a simple, atomic operation... > yet, you've got a function-call, an intermediary variable, a boolean > test, and an unset statement repeating the name of the array you're > deleting from. > > This should be a simple statement or function/method-call, and in > most other languages it would be... How simple is it? Does it: 1) Remove one occurrence of the element (presumably the first) or all? 2) Reindex the array (as someone else argued was necessary to make it "properly indexed" afterwards) or not? 3) Modify the array in-place or return a modified array? 4) Use type-strict or normal comparisons? Personally, I like Python's list.remove(x), which I think might be what he wants. Certainly it's what I want when I need to remove a list item. See: http://docs.python.org/tutorial/datastructures.html* *According to the docs, it does this: " Remove the first item from the list whose value is/x/. It is an error if there is no such item." So to answer you, 1) one, 2), no, 3) in-place, 4) type-strict (I don't see how a weakly-typed comparison for identifying an array value would help anyone). That's sixteen different interpretations of "remove a given value from an array" right there. Leave support for any of them out and someone is going to complain that they have to write a function to do what should be a "simple statement". Support all of them and there will probably _still_ be someone who wants their own particular set of circumstances catered for without having to write their own function to do it. Just my 2¢. -- Andrew Faulds http://ajf.me/
Re: [PHP-DEV] re: removing an item from an array
On 17/08/12 22:41, Rasmus Lerdorf wrote: On 08/17/2012 05:35 PM, Rasmus Schultz wrote: Most other languages have more than one collection-type... since PHP has only the single, hybrid array-type which acts both as a hash and as an array, something like this ought to be available. I don't know why everyone is so eager to jump up and argue against something this simple, basic and useful. The fact that this is missing is an oversight - just look at the number of solutions people come up with. For what? I want to remove and object from a list. Not an exotic and crazy requirement, is it? It just isn't the sort of thing that should require any substantial thinking or typing. And it doesn't help make codebases more legible when people come up with 25 different ways to do it. The problem is that it is a rather unusual thing to do. I don't mean removing an element, that is very common, but you are implying that you know you don't have duplicates and you want a fast way to remove an element by value in that case. To me that means you built your array badly. If the values are unique then they should be the keys, or at least a representation of the value should be the key such that you don't need to scan the entire hash for the element when you need to access it. And removal is just like any other access. -Rasmus Hmm. I can think of a particular instance I've needed to remove an item from an array by value, and where keys wouldn't be an option. In PHP you can only have string or int keys, you can't have object keys. In Python, I've used Twisted (an excellent asynchronous OOP networking framework) to write client-server applications. One thing I did was maintain a list of clients (that is, a Python list). When a client disconnected, I would do list.remove(client). Of course there might be better ways to implement this, but it was simple and worked. Anything wrong with allowing the same in PHP? -- Andrew Faulds http://ajf.me/ -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] re: removing an item from an array
Rasmus Schultz wrote: > I disagree - this is (or should be) a simple, atomic operation... > yet, you've got a function-call, an intermediary variable, a boolean > test, and an unset statement repeating the name of the array you're > deleting from. > > This should be a simple statement or function/method-call, and in > most other languages it would be... How simple is it? Does it: 1) Remove one occurrence of the element (presumably the first) or all? 2) Reindex the array (as someone else argued was necessary to make it "properly indexed" afterwards) or not? 3) Modify the array in-place or return a modified array? 4) Use type-strict or normal comparisons? That's sixteen different interpretations of "remove a given value from an array" right there. Leave support for any of them out and someone is going to complain that they have to write a function to do what should be a "simple statement". Support all of them and there will probably _still_ be someone who wants their own particular set of circumstances catered for without having to write their own function to do it. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On Fri, Aug 17, 2012 at 11:35 PM, Rasmus Schultz wrote: > Most other languages have more than one collection-type... since PHP has > only the single, hybrid array-type which acts both as a hash and as an > array, something like this ought to be available. > > I don't know why everyone is so eager to jump up and argue against > something this simple, basic and useful. The fact that this is missing is > an oversight - just look at the number of solutions people come up with. > For what? Could we please stop these pseudo-arguments? "simple, basic and useful. The fact that this is missing is an oversight"? Do you have anything to back up these claims? I can't remember to have been in a situation where I wanted to remove a value from an array. Simply because that's a slow operation. When you have to do it you *usually* have chosen the wrong datastructure. And in the cases where you do need it, you can easily do it with array_search. Where is the issue? Also, as I already pointed out, "removing a value from an array" is not well defined. Do you mean to only remove the first occurrence of the value? Only the last? All of them? Do you want to have special functions for all of those? Furthermore, why do you keep coming back to the "There exists more than one solution to this problem" argument? Everything can be done in a large number of ways. And people come up with a lot of ways, depending on the situation. You can output a string with echo, with print, with concatenation, with interpolation, with multi-arg echo, with printf, etc. So sure, there are also multiple ways to remove values from an array. What's the issue with that? Nikita -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
On 08/17/2012 05:35 PM, Rasmus Schultz wrote: > Most other languages have more than one collection-type... since PHP has > only the single, hybrid array-type which acts both as a hash and as an > array, something like this ought to be available. > > I don't know why everyone is so eager to jump up and argue against > something this simple, basic and useful. The fact that this is missing > is an oversight - just look at the number of solutions people come up > with. For what? > > I want to remove and object from a list. Not an exotic and crazy > requirement, is it? It just isn't the sort of thing that should require > any substantial thinking or typing. > > And it doesn't help make codebases more legible when people come up with > 25 different ways to do it. The problem is that it is a rather unusual thing to do. I don't mean removing an element, that is very common, but you are implying that you know you don't have duplicates and you want a fast way to remove an element by value in that case. To me that means you built your array badly. If the values are unique then they should be the keys, or at least a representation of the value should be the key such that you don't need to scan the entire hash for the element when you need to access it. And removal is just like any other access. -Rasmus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] re: removing an item from an array
Most other languages have more than one collection-type... since PHP has only the single, hybrid array-type which acts both as a hash and as an array, something like this ought to be available. I don't know why everyone is so eager to jump up and argue against something this simple, basic and useful. The fact that this is missing is an oversight - just look at the number of solutions people come up with. For what? I want to remove and object from a list. Not an exotic and crazy requirement, is it? It just isn't the sort of thing that should require any substantial thinking or typing. And it doesn't help make codebases more legible when people come up with 25 different ways to do it. On Fri, Aug 17, 2012 at 5:23 PM, Rasmus Lerdorf wrote: > On 08/17/2012 05:21 PM, Rasmus Schultz wrote: > >> > >> if(($key = array_search($del_val, $messages)) !== false) { > >> unset($messages[$key]); > >> } > >> > >> Nothing horrible here. > >> > > > > I disagree - this is (or should be) a simple, atomic operation... > > yet, you've got a function-call, an intermediary variable, a boolean > test, > > and an unset statement repeating the name of the array you're deleting > from. > > > > This should be a simple statement or function/method-call, and in most > > other languages it would be... > > Really? I can't think of a single language that has a call to remove an > element by value in a key-value hash. Do you have some examples? What do > you do with duplicates? > > -Rasmus > >
Re: [PHP-DEV] re: removing an item from an array
On 08/17/2012 05:21 PM, Rasmus Schultz wrote: >> >> if(($key = array_search($del_val, $messages)) !== false) { >> unset($messages[$key]); >> } >> >> Nothing horrible here. >> > > I disagree - this is (or should be) a simple, atomic operation... > yet, you've got a function-call, an intermediary variable, a boolean test, > and an unset statement repeating the name of the array you're deleting from. > > This should be a simple statement or function/method-call, and in most > other languages it would be... Really? I can't think of a single language that has a call to remove an element by value in a key-value hash. Do you have some examples? What do you do with duplicates? -Rasmus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DEV] re: removing an item from an array
> > if(($key = array_search($del_val, $messages)) !== false) { > unset($messages[$key]); > } > > Nothing horrible here. > I disagree - this is (or should be) a simple, atomic operation... yet, you've got a function-call, an intermediary variable, a boolean test, and an unset statement repeating the name of the array you're deleting from. This should be a simple statement or function/method-call, and in most other languages it would be...