note 90766 deleted from function.array-merge by danbrown

From: Date: Fri, 08 May 2009 15:27:12 +0000
Subject: note 90766 deleted from function.array-merge by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154366@lists.php.net to get a copy of this message
Note Submitter: jjfitzgerald AT googlesmail DOT com ---- @carrox: The $array += array() syntax only works with explicitly associative arrays. <?php // doesn't merge $a = array('test'); $a += array('test2'); var_dump($a); ?> Output: array(1) { [0]=>string(4) "test" } <?php // associative array works $a = array('test' => 'value'); $a += array('test2' => 'value2'); var_dump($a); ?> Output: array(2) { ["test"]=>string(5) "value" ["test2"]=>string(6) "value2" } <?php // specifying index values works too $a = array(0 => 'test'); $a += array(1 => 'test2'); var_dump($a); ?> Output: array(2) { [0]=>string(4) "test" [1]=>string(7) "test2" }

« previous php.notes (#154366) next »