> > This is my favourite way of removing a value: > $kv = array( 1 => 'a', 2 => 'b', 3 => 'c'); > $vk = array_flip($kv); > unset($vk['b']); > $kv = array_flip($vk);
That doesn't make any sense. What if the values are present more than once? array_flip will cause the keys to be overwritten. $array = array('foo','bar','baz','baz'); $flipped_array = array_flip($array); unset($flipped_array['foo']); $array = array_flip($flipped_array); var_dump($array); 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). Unlike most other languages PHP's arrays aren't really arrays, because they don't create a list of values, but instead create an ordered hashmap, which in-turn solves a wide variety of general problems such as the ability to create dictionaries as well as ordered lists, which -- when combining all general use cases that the PHP array aims to solve -- is otherwise going to require having additional multiple primitives for each use case. For example in Python you need a combination of Tuples and Arrays to achieve similar map structures. PHP aims to make this a more simplified general use case primitive by abstracting away most of this low-level work for you in the user-space code. I don't wish to degrade anyone's contributions to this thread, but this really is the perfect example of making a lot of fuss over nothing on the mailing list and an example of the kinds of discussion we should be avoiding when there are so many other important problems we can solve. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php