Re: removing an item from an array

From: Date: Wed, 15 Aug 2012 20:23:57 +0000
Subject: Re: removing an item from an array
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-62203@lists.php.net to get a copy of this message
I like that chose 42 for the value. You win, and I completely agree. On Wed, Aug 15, 2012 at 4:22 PM, Stas Malyshev <smalyshev@sugarcrm.com>wrote: > Hi! > > > How come there is no straight-foward obvious way to simply remove a given > > value from an array? > > The same reason there's no simple way to undefine variable whose value > is 42 without knowing the variable name. Array is a container indexed by > keys, not values. So if you've got just a value, there's no way to know > if it's in the container at all, and if it is, where it is, except for > going through all the values and checking if any of them is equal to > what you nedd. > > > 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. > > -- > Stanislav Malyshev, Software Architect > SugarCRM: http://www.sugarcrm.com/ > (408)454-6900 ext. 227 > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >

« previous php.internals (#62203) next »