note 76020 deleted from function.array-merge by danbrown
| From: | danbrown@php.net | Date: | Mon, 20 Jun 2011 15:18:46 +0000 |
| Subject: | note 76020 deleted from function.array-merge by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-180732@lists.php.net to get a copy of this message | ||
Note Submitter: jyee
----
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.