|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-15 04:14 UTC] shrub at yahoo dot com
Description:
------------
When you call array_pop on an array, you only get back the
value. It would be nice if there was an array_key_value_pop
function that returned both the key and the value.
Reproduce code:
---------------
function array_key_value_pop (&$a) {
end($a);
$lastItem = each($a);
array_pop($a);
return array($lastItem["key"] => $lastItem["value"]);
}
Expected result:
----------------
$a = array ("red"=>"12a", "fish" => "rock", "blue" => "xyz");
print_r (array_key_value_pop($a));
Array
(
[blue] => xyz
)
print_r($a);
Array
(
[red] => 12a
[fish] => rock
)
Actual result:
--------------
n/a
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 21:00:01 2025 UTC |
Closing this as this is already possible simply by using array_splice: $a = array ("red"=>"12a", "fish" => "rock", "blue" => "xyz"); var_dump(array_splice($a, -1)); var_dump(array_splice($a, -1)); var_dump(array_splice($a, -1)); The pop operation is intended for use with stacks and you don't need the key in that case.