note 76020 added to function.array-merge

From: Date: Tue, 26 Jun 2007 23:14:49 +0000
Subject: note 76020 added to function.array-merge
Groups: php.notes 
Request: Send a blank email to php-notes+get-128006@lists.php.net to get a copy of this message
in regards to Joe's problem with arr1 + arr2 versus array_merge(arr1, arr2) - this seems to have been fixed in php 5.2.3 $arr1['foo'] = 'bar'; $arr2['bar'] = 'baz'; $arr3 = $arr1 +$arr2; print_r($arr3) will produce: array( 'foo' => 'bar', 'bar' => 'baz' ); I should also note that array_merge() will convert strings of integers into integers for php 5.2.3. For example: $arr1['007'] = 'james bond'; $arr2['008'] = 'some other spy'; $arr3 = array_merge($arr1, $arr2); print_r($arr3) will produce: array( 7 => 'james bond', 8 => 'some other spy' ); so if you must maintain leading zeros, it's best to use $arr1 + $arr2 instead of array_merge. ---- Server IP: 208.69.120.35 Probable Submitter: 67.88.110.178 ---- Manual Page -- http://www.php.net/manual/en/function.array-merge.php Edit -- https://master.php.net/note/edit/76020 Del: integrated -- https://master.php.net/note/delete/76020/integrated Del: useless -- https://master.php.net/note/delete/76020/useless Del: bad code -- https://master.php.net/note/delete/76020/bad+code Del: spam -- https://master.php.net/note/delete/76020/spam Del: non-english -- https://master.php.net/note/delete/76020/non-english Del: in docs -- https://master.php.net/note/delete/76020/in+docs Del: other reasons-- https://master.php.net/note/delete/76020 Reject -- https://master.php.net/note/reject/76020 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128006) next »