Merging Associative Arrays
by
on 11-17-2009 at 02:36 PM (218 Views)
I know I'm going to forget this so I'm making a note of it here.
If you have two associative arrays...
... and want to merge them, the array before the plus operator overwrites the one after it:PHP Code:$test1['fruit'] = "banana";
$test1['veg'] = "cabbage";
$test2['fruit'] = "banana";
$test2['veg'] = "lettuce";
Results in:PHP Code:print_r($test1 + $test2);
print_r($test2 + $test1);
Must remember... must remember...Array ( [fruit] => banana [veg] => cabbage )
Array ( [fruit] => banana [veg] => lettuce )








Email Blog Entry