note 115209 added to function.array-merge

From: Date: Thu, 12 Jun 2014 13:57:48 +0000
Subject: note 115209 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-199672@lists.php.net to get a copy of this message
An addition to what Julian Egelstaff above wrote - the array union operation (+) is not doing an array_unique - it will just not use the keys that are already defined in the left array. The difference between union and merge can be seen in an example like this: <?php $arr1['one'] = 'one'; $arr1['two'] = 'two'; $arr2['zero'] = 'zero'; $arr2['one'] = 'three'; $arr2['two'] = 'four'; $arr3 = $arr1 + $arr2; var_export( $arr3 ); # array ( 'one' => 'one', 'two' => 'two', 'zero' => 'zero', ) $arr4 = array_merge( $arr1, $arr2 ); var_export( $arr4 ); # array ( 'one' => 'three', 'two' => 'four', 'zero' => 'zero', ) ?> ---- Server IP: 72.52.91.14 Probable Submitter: 82.103.112.60 ---- Manual Page -- http://php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/115209 Del: integrated -- https://master.php.net/note/delete/115209/integrated Del: useless -- https://master.php.net/note/delete/115209/useless Del: bad code -- https://master.php.net/note/delete/115209/bad+code Del: spam -- https://master.php.net/note/delete/115209/spam Del: non-english -- https://master.php.net/note/delete/115209/non-english Del: in docs -- https://master.php.net/note/delete/115209/in+docs Del: other reasons-- https://master.php.net/note/delete/115209 Reject -- https://master.php.net/note/reject/115209 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199672) next »