#11074 [Bgs]: array_splice used to insert associative array forgets first key

From: Date: Fri, 04 Mar 2005 11:01:39 +0000
Subject: #11074 [Bgs]: array_splice used to insert associative array forgets first key
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-74827@lists.php.net to get a copy of this message
ID: 11074 Updated by: techtonik@php.net Reported By: symetrie at online dot fr Status: Bogus Bug Type: Arrays related Operating System: Linux SuSE 6.4 -PHP Version: 4.0.4pl1 +PHP Version: 4.3.10 New Comment: array_splice doesn't preserve keys from replacement arrays. I wonder if it is possible to add optional "preserve_keys" parameter in PHP5? Previous Comments: ------------------------------------------------------------------------ [2002-02-26 21:37:46] yohgaki@php.net The version of PHP that this bug was reported in is too old. Please try to reproduce this bug in the latest version of PHP (available from http://www.php.net/downloads.php If you are still able to reproduce the bug with one of the latest versions of PHP, please change the PHP version on this bug report to the version you tested and change the status back to "Open". ------------------------------------------------------------------------ [2001-05-23 22:04:42] symetrie at online dot fr 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 this bug report at http://bugs.php.net/?id=11074&edit=1

« previous php.bugs (#74827) next »