Bug #8032 Updated: array_splice made array keys bad
| From: | jason@php.net | Date: | Mon, 20 Aug 2001 02:56:11 +0000 |
| Subject: | Bug #8032 Updated: array_splice made array keys bad | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-63792@lists.php.net to get a copy of this message | ||
ID: 8032
Updated by: jason
Reported By: nimrod@ambernet.kiev.ua
Old Status: Open
Status: Closed
Bug Type: Arrays related
Operating System: FreeBSD 4.2-Release
PHP Version: 4.0.3pl1
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2000-11-29 10:44:33] nimrod@ambernet.kiev.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
------------------------------------------------------------------------
Edit this bug report at http://bugs.php.net/?id=8032&edit=1