|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-11-29 10:44 UTC] nimrod at ambernet dot kiev dot ua
<?
$a["e"]="e";
$a["r"]="r";
$a["11"]="111";
$a["22"]="222";
array_splice ($a,0,1);
foreach ($a as $k=>$v) {
echo "$k=$v<br>";
}
?>
produce:
r=r
0=111
1=222
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 06:00:02 2025 UTC |
This is actually not a bug. What you are running in to is php's auto-type conversion when you are building your array. $a["11"] automagicly will become a numeric index of $a[11]. Due to the way that array_splice is designed, the array is completly changed, and thus the numeric indexes are reset. If you wish to prevent this from occuring, prefix the numeric string with 0. ie <? $a["e"]="e"; $a["r"]="r"; $a["011"]="111"; $a["022"]="222"; array_splice ($a,0,1); foreach ($a as $k=>$v) { echo "$k=$v<br>"; } ?> will produce r=r 011=111 022=222 -Jason