Possible Duplicate:
PHP: Merge 2 Multidimensional Arrays
I have these arrays and I want to merge them into one array.
$arrayAAA[0]['name'] = "stackoverflow";
$arrayBBB[0]['color'] = "white";
$arrayCCC[0]['media'] = "web";
I want to merge these like this.
$newArray[0]['name'] //"stackoverflow"
$newArray[0]['color'] //"white"
$newArray[0]['media'] //"web"
If anyone knows how to do this, please give me a help.
I thought I could merge them by using array_merge()
, but this function doesn't work in my case.
Thanks so much in advance!
I dont know how much time you have wasted finding the solution while you could have written a manual one.
foreach(array($arrayAAA, $arrayBBB, $arrayCCC) as $v){
foreach($v as $iv){
$result[key($iv)] = $iv[key($iv)];
}
}
CodePad
I think you want to use array_merge()
, not merge_array()
So, this does not work either?
$x = array();
$x[0] = array_merge($arrayA[0], $arrayB[0], ...);
There is also array_merge_recursive function. But I am pretty sure it would only append each sub-array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With