note 36765 deleted from function.array-pop by aharvey
| From: | aharvey@php.net | Date: | Wed, 20 Nov 2013 22:49:35 +0000 |
| Subject: | note 36765 deleted from function.array-pop by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197599@lists.php.net to get a copy of this message | ||
Note Submitter:
----
Be aware that using array_pop on an associative array that uses a numeric string as a key changes
the key:
<?php
$stack= array("12" => "green", "54" => "brown",
"672" => "blue");
print_r($stack);
$fruit = array_pop($stack);
print_r($stack);
?>
Results of execution:
Array
(
[12] => green
[54] => brown
[672] => blue
)
Array
(
[0] => green
[1] => brown
)
However, if there is a non-numeric character in the key, the key will be maintained:
<?php
$stack= array("g1" => "green", "b1" => "brown",
"b2" => "blue");
print_r($stack);
$fruit = array_pop($stack);
print_r($stack);
?>
Results of execution:
Array
(
[g1] => green
[b1] => brown
[b2] => blue
)
Array
(
[g1] => green
[b1] => brown
)