View RSS Feed

Nick's Hotaru CMS Blog

Merging Associative Arrays

Rate this Entry
I know I'm going to forget this so I'm making a note of it here.

If you have two associative arrays...

PHP Code:
$test1['fruit'] = "banana";
$test1['veg'] = "cabbage";

$test2['fruit'] = "banana";
$test2['veg'] = "lettuce"
... and want to merge them, the array before the plus operator overwrites the one after it:

PHP Code:
print_r($test1 $test2); 
print_r($test2 $test1); 
Results in:

Array ( [fruit] => banana [veg] => cabbage )
Array ( [fruit] => banana [veg] => lettuce )
Must remember... must remember...

Submit "Merging Associative Arrays" to Digg Submit "Merging Associative Arrays" to del.icio.us Submit "Merging Associative Arrays" to StumbleUpon Submit "Merging Associative Arrays" to Google

Comments

Trackbacks

Total Trackbacks 0
Trackback URL: