Req #34506 [Csd->Wfx]: would like an array_key_value_pop function
| From: | aharvey@php.net | Date: | Sat, 14 Apr 2012 02:59:57 +0000 |
| Subject: | Req #34506 [Csd->Wfx]: would like an array_key_value_pop function | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-169579@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=34506&edit=1
ID: 34506
Updated by: aharvey@php.net
Reported by: shrub at yahoo dot com
Summary: would like an array_key_value_pop function
-Status: Closed
+Status: Wont fix
Type: Feature/Change Request
Package: *General Issues
Operating System: n/a
PHP Version: 5.1.0RC1
-Assigned To: nikic
+Assigned To:
Block user comment: N
Private report: N
Previous Comments:
------------------------------------------------------------------------
[2012-04-13 20:39:07] nikic@php.net
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.
------------------------------------------------------------------------
[2005-09-15 04:14:56] 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
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=34506&edit=1