note 90766 added to function.array-merge

From: Date: Fri, 08 May 2009 15:00:45 +0000
Subject: note 90766 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-154364@lists.php.net to get a copy of this message
@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" } ---- Server IP: 208.69.120.35 Probable Submitter: 24.136.116.91 ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/90766 Del: integrated -- https://master.php.net/note/delete/90766/integrated Del: useless -- https://master.php.net/note/delete/90766/useless Del: bad code -- https://master.php.net/note/delete/90766/bad+code Del: spam -- https://master.php.net/note/delete/90766/spam Del: non-english -- https://master.php.net/note/delete/90766/non-english Del: in docs -- https://master.php.net/note/delete/90766/in+docs Del: other reasons-- https://master.php.net/note/delete/90766 Reject -- https://master.php.net/note/reject/90766 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154364) next »