Re: removing an item from an array

From: Date: Thu, 16 Aug 2012 06:56:15 +0000
Subject: Re: removing an item from an array
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-62214@lists.php.net to get a copy of this message
On 2012-08-16 17:55, Sherif Ramadan wrote:
That doesn't make any sense. What if the values are present more than once? array_flip will cause the keys to be overwritten. Not to mention converting all of the array's elements to strings and/or integers.
Now your array is something completely different from what you wanted. The solution stated earlier is the most sane one (just using array_keys() with a search value). The problem isn't very complicated and doesn't require a complex solution. This thread is overstating a rudimentary problem (and that's the lack of understanding PHP arrays). I was actually alluding to something more disturbing:
<?php $array = [['foo', 'bar'], ['wibble', 'fnord']]; $array = array_diff($array, [['wibble', 'fnord']]); print_r($array); ?> ...which makes array_diff and its ilk only useful for scalar elements (hence the need for the more complicated approach using array_keys(), which provides a strictness flag).

Thread (91 messages)

« previous php.internals (#62214) next »