note 8585 added to array_unshift
| From: | matt at synergie dot net | Date: | Tue, 19 Sep 2000 02:20:49 +0000 |
| Subject: | note 8585 added to array_unshift | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-5202@lists.php.net to get a copy of this message | ||
The behaviour of unshift nearly caught me out.
Not only is the item added at the start of the list but the list is re-indexed too.
<?php
$a = array(5=>"five", 6 =>"six", 20 => "twenty");
while(list($key, $value) = each($a))
echo "k: $key v: $value<BR>\n";
echo "<BR>\n";
array_unshift($a, "zero");
while(list($key, $value) = each($a))
echo "k: $key v: $value<BR>\n";
?>
k: 5 v: five
k: 6 v: six
k: 20 v: twenty
k: 0 v: zero
k: 1 v: five
k: 2 v: six
k: 3 v: twenty
http://www.php.net/manual/function.array-unshift.php