|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-11 20:52 UTC] tony2001@php.net
[2007-01-11 20:57 UTC] wgilk at reliablesites dot com
[2007-01-11 21:15 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 17:00:01 2025 UTC |
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 ----