#30305 [Ver->Opn]: array_splice() discards keys of incoming array (needs 'preserve_keys' parameter)
| From: | sniper@php.net | Date: | Tue, 29 Nov 2005 13:23:04 +0000 |
| Subject: | #30305 [Ver->Opn]: array_splice() discards keys of incoming array (needs 'preserve_keys' parameter) | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-89392@lists.php.net to get a copy of this message | ||
ID: 30305
Updated by: sniper@php.net
-Summary: array_splice() discards keys of incoming array
Reported By: conciseusa at yahoo dot com
-Status: Verified
+Status: Open
-Bug Type: Arrays related
+Bug Type: Feature/Change Request
Operating System: *
PHP Version: 5CVS, 4CVS (2004-09-29)
Previous Comments:
------------------------------------------------------------------------
[2005-03-04 12:12:55] techtonik@php.net
See also: http://bugs.php.net/bug.php?id=11074
------------------------------------------------------------------------
[2004-10-01 18:20:59] conciseusa at yahoo dot com
Description:
------------
It seems to be impossible to replace a key in associative array with
another associative array : array_splice always add a '0' or next
unused numeric key for incoming array... This would seem to be a bug.
Reproduce code:
---------------
<?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 )
// 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 )
?>
Expected result:
----------------
// Should be :
// Array ( [a] => AA [z] => Array ( [z1] => ZZ1 [z2] => ZZ2 ) [1] =>
XX
[c] => CC )
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30305&edit=1