note 65992 deleted from function.array-merge-recursive by googleguy

From: Date: Tue, 22 Oct 2013 14:58:20 +0000
Subject: note 65992 deleted from function.array-merge-recursive by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-197254@lists.php.net to get a copy of this message
Note Submitter: Vladimir Kornea ---- The documentation for array_merge_recursive() states that string keys are preserved while numeric keys are renumbered. What's not obvious is that string keys which happen to be numeric are NOT preserved, but renumbered: $a = array('5' => array('blue')); $b = array('5' => array('red')); $c = array_merge_recursive($a, $b); print_r($c); Output: Array ( [0] => Array ( [0] => blue ) [1] => Array ( [0] => red ) ) If the key '5' were treated as a string, the resulting array would be this: Array ( [5] => Array ( [0] => blue [1] => red ) )

« previous php.notes (#197254) next »