note 36765 added to function.array-pop
| From: | php-general at lists dot php dot net | Date: | Tue, 21 Oct 2003 17:46:26 +0000 |
| Subject: | note 36765 added to function.array-pop | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-59051@lists.php.net to get a copy of this message | ||
Be aware that using array_pop on an associative array that uses a numeric string as a key changes
the key:
$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:
$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
)
----
Manual Page -- http://www.php.net/manual/en/function.array-pop.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+36765
Delete -- http://master.php.net/manage/user-notes.php?action=delete+36765&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+36765&report=yes
Search -- http://master.php.net/manage/user-notes.php