Supposing I've this array:
Array
(
[country] => Array
(
[0] => France
[1] => Canada
)
[capital] => Array
(
[0] => Paris
[1] => Ottawa
)
[other] => value
)
Is it possible to merge the country and capital arrays ?
The desired output is the following:
Array
(
[countries] => Array
(
Array
(
[country] => France
[capital] => Paris
)
Array
(
[country] => Canada
[capital] => Ottawa
)
)
[other] => value
)
What I tried:
$result = array();
foreach($arr as $key=>$array) {
$result[$key] = array_merge($array, $arr2[$key]);
}
[other] => value? how do you know which field to combine?[other] => valueshould remain in the new array. For how to combine, the value should be merged in the key order. So the first ofcountryshould go with the first ofcapital...