Bug #11074: array_splice used to insert associative array forgets first key
| From: | symetrie at online dot fr | Date: | Thu, 24 May 2001 02:04:42 +0000 |
| Subject: | Bug #11074: array_splice used to insert associative array forgets first key | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-56574@lists.php.net to get a copy of this message | ||
From: symetrie@online.fr
Operating system: Linux SuSE 6.4
PHP version: 4.0.4pl1
PHP Bug Type: Arrays related
Bug description: array_splice used to insert associative array forgets first key
It seems to be impossible to replace a key in associative array with another array : array_splice
always add a '0' key... Feature or bug ?
<?php
$a = array("a" => "AA", "b" => "BB",
"c" => "CC");
$a2 = $a;
$z = array("z" =>
array("z1"=>"ZZ1","z2"=>"ZZ2"), "x"
=>"XX");
// 1 try to replace "b"=>"BB" by contents of $z
array_splice($a, 1, 1, $z);
print_r($a);
// produces : Array ( [a] => AA [0] => Array ( [z1] => ZZ1 [z2] => ZZ2 ) [1] => XX
[c] => CC )
echo "<hr>";
// 2 try to replace "b"=>"BB" by contents of $z as in manual
array_splice($a, 1, 1, array($z));
print_r($a);
// produces : Array ( [a] => AA [0] => Array ( [z] => Array ( [z1] => ZZ1 [z2] => ZZ2
) [x] => XX ) [1] => XX [c] => CC )
// I'd like :
// Array ( [a] => AA [z] => Array ( [z1] => ZZ1 [z2] => ZZ2 ) [1] => XX [c] => CC
)
?>
--
Edit Bug report at: http://bugs.php.net/?id=11074&edit=1