Re: Re: [PHP-DEV] removing an item from an array
| From: | Morgan L. Owens | Date: | Wed, 15 Aug 2012 23:59:15 +0000 |
| Subject: | Re: Re: [PHP-DEV] removing an item from an array | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62209@lists.php.net to get a copy of this message | ||
On 2012-08-16 08:27, Nikita Popov wrote:
On Wed, Aug 15, 2012 at 10:22 PM, Stas Malyshev <smalyshev@sugarcrm.com> wrote:Hi!Btw, deleting all values (not just the first) is also very easy currently: foreach (array_keys($array, $delValue) as $key) {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.unset($array[$key]);} $array = array_diff($array, [$delValue]);