On Wed, Aug 15, 2012 at 7:59 PM, Morgan L. Owens <pack...@nznet.gen.nz>wrote:
> On 2012-08-16 08:27, Nikita Popov wrote: > >> On Wed, Aug 15, 2012 at 10:22 PM, Stas Malyshev <smalys...@sugarcrm.com> >> wrote: >> >>> Hi! >>> >>> 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: >>>> >>> >>> I see: >>> if(($key = array_search($del_val, $messages)) !== false) { >>> unset($messages[$key]); >>> } >>> >>> Nothing horrible here. >>> >> >> Btw, deleting all values (not just the first) is also very easy currently: >> >> foreach (array_keys($array, $delValue) as $key) { >> unset($array[$key]); >> } >> >> $array = array_diff($array, [$delValue]); > > > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > http://php.net/array_flip 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);