Req #30305 [Opn->Dup]: array_splice() discards keys of incoming array (needs 'preserve_keys' parameter)

From: Date: Thu, 17 Apr 2014 14:37:19 +0000
Subject: Req #30305 [Opn->Dup]: 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-185329@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=30305&edit=1 ID: 30305 Updated by: levim@php.net Reported by: conciseusa at yahoo dot com Summary: array_splice() discards keys of incoming array (needs 'preserve_keys' parameter) -Status: Open +Status: Duplicate Type: Feature/Change Request -Package: Feature/Change Request +Package: Arrays related -Operating System: * +Operating System: Irrelevant -PHP Version: 5CVS, 4CVS (2004-09-29) +PHP Version: * Block user comment: N Private report: N New Comment: Duplicate of https://bugs.php.net/bug.php?id=11074 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 https://bugs.php.net/bug.php?id=30305&edit=1

« previous php.bugs (#185329) next »