note 123212 deleted from function.array-merge by salathe

From: Date: Mon, 06 Sep 2021 22:43:10 +0000
Subject: note 123212 deleted from function.array-merge by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-216875@lists.php.net to get a copy of this message
Note Submitter: pike-common at kw dot nl ---- When mixing string keys and numeric keys, numeric keys are still renumbered after merge. <?php $test1= array("foo"=>"rfoo1",2=>"r21","bar"=>"rbar1"); $test2= array("foo"=>"rfoo2",2=>"r22","bar"=>"rbar2"); var_dump(array_merge($test1,$test2)); ?> array(4) { ["foo"]=> string(5) "rfoo2" [0]=> string(3) "r21" ["bar"]=> string(5) "rbar2" [1]=> string(3) "r22" } adding arrays doesn't: <?php var_dump($test2+$test1); ?> array(3) { ["foo"]=> string(5) "rfoo2" [2]=> string(3) "r22" ["bar"]=> string(5) "rbar2" }

« previous php.notes (#216875) next »