On Tue, Aug 21, 2012 at 7:45 PM, Yasuo Ohgaki <yohg...@ohgaki.net> wrote: > > Hi, > > 2012/8/16 Rasmus Schultz <ras...@mindplay.dk>: > > How come there is no straight-foward obvious way to simply remove a given > > value from an array? > > > > Just look at the number of horrible ways people solve this obvious problem: > > > > http://stackoverflow.com/questions/7225070/php-array-delete-by-value-not-key > > > > Shouldn't we have something simple, like: > > > > array_remove($array, $value) : array (returns a new array) > > > > and/or > > > > array_delete(&$array, $value) : bool (modifies array directly) > > > > ? > > It was amazing that this thread has close to 90 mails. > > I've added some use cases of array_udelete() to wiki, since > some people fails to see how it could be useful. I also bring > back to array_walk() version of equivalent example. I just > don't see any reason why we should replace it with slower > foreach() version. > > I think the RFC page is almost complete. > > https://wiki.php.net/rfc/array_delete > > Any more comments? > > -- > Yasuo Ohgaki > yohg...@ohgaki.net
Take a look at: http://php.net/manual/en/function.array-walk.php#refsect1-function.array-walk-parameters Look at funcname parameter. Notice: > 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. If > the callback does not respect this requirement, the behavior of this function > is undefined, and unpredictable. I'm just going to change the behavior back when you switch it to array_walk. It's less clear and technically undefined. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php