#40101 [WFx]: Please add an array_remove function
| From: | tony2001@php.net | Date: | Thu, 11 Jan 2007 21:15:29 +0000 |
| Subject: | #40101 [WFx]: Please add an array_remove function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-107503@lists.php.net to get a copy of this message | ||
ID: 40101
Updated by: tony2001@php.net
Reported By: wgilk at reliablesites dot com
Status: Wont fix
Bug Type: Feature/Change Request
Operating System: ALL
PHP Version: 6CVS-2007-01-11 (CVS)
New Comment:
That's what PHP is about - it's a language, not just a limited stack of
tools.
Previous Comments:
------------------------------------------------------------------------
[2007-01-11 20:57:35] wgilk at reliablesites dot com
But there is no function to do this in php. I relize it's
trivial, but it would still be very use in many applications.
------------------------------------------------------------------------
[2007-01-11 20:52:41] tony2001@php.net
You can use the function from your example instead.
Adding more basic functions to the core doesn't make any sense.
------------------------------------------------------------------------
[2007-01-11 20:45:57] wgilk at reliablesites dot com
Description:
------------
It would be very nice to have an array_remove (or some other
name) function to do what the code below illustrates.
The point of the function is to allow use to retrieve the
value of a particular key in an array, and remove it from the
array at the same time. Think of it as array_shift(), but with
the ability to define the key that gets shifted.
Reproduce code:
---------------
function array_remove ($key, &$array) {
if (! isset ($array[$key])) return false;
$return = $array[$key];
unset ($array[$key]);
return $return;
}
$array = array ('food' => 'taco', 'drink' => 'juice');
$value = array_remove ('food', $array);
print_r ($array);
print $value;
Expected result:
----------------
FROM print_r:
----
array (
'drink' => 'juice
)
----
FROM print:
----
taco
----
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40101&edit=1