|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-03-04 12:12 UTC] techtonik@php.net
[2014-04-17 14:37 UTC] levim@php.net
-Status: Open
+Status: Duplicate
-Package: Feature/Change Request
+Package: Arrays related
-Operating System: *
+Operating System: Irrelevant
-PHP Version: 5CVS, 4CVS (2004-09-29)
+PHP Version: *
[2014-04-17 14:37 UTC] levim@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 17:00:02 2025 UTC |
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 )