
October 15th, 2012, 02:19 PM
|
 |
Contributing User
|
|
|
|
|
Merging Associative Arrays with Overwrite/Append
Alright, I've been around long enough where I should know how to do this by now. I have worked around this in the past by looping through both arrays and coming up with a third array that contains the appropriate values. So here is my test data...
PHP Code:
$defaults = Array(
'attr'=>Array(
'class'=>Array('beta')
,'id'=>'beta'
)
);
$newArray = Array(
,'attr'=> Array(
'id'=>'test'
),'style' => Array(
'text-align'=>'left'
)
);
//I want the defaults array to change beta to test and append
//the style on it... so the defaults array ends up looking like
//Array(id=>test, attr=>Array(class=>Array(beta),id=>test),
//style=>Array(text-align=>left)
I have tried array_merge and adding the arrays together. Adding the arrays appends the style which works but I can't figure out how to overwrite the 'id' value without looping through the array.
Is there any tips on how to accomplish this more efficiently?
Last edited by pgrinPDT : October 15th, 2012 at 02:22 PM.
|