I have a multidimensional array with an unknown structure and unknown number of items. I need to get a "flater" array compiled from particular keys, like in following example:
Input
$input = array(
1 => array(
'color' => 'blue',
'haircut' => 'mullet',
'satisfaction' => 'mild',
'recursion' => array(...)
),
2 => array(
'color' => 'green',
'haircut' => 'mushroom',
'fashionable' => true,
'recursion' => array(...)
),
3 => array(
'color' => 'yellow',
'haircut' => 'beehive',
'awkward' => false,
'recursion' => array(...)
),
...
);
Output (merged array from above)
$output = array(
'color' => 'yellow',
'haircut' => 'beehive',
'satisfaction' => 'mild',
'fashionable' => true,
'awkward' => false,
'recursion' => array(...)
);
The ideal way, I think, would be to use array_replace_recursive($input[0],$input[1],$input[2], ...), right? The problem is I don't know the exact number of keys in $input array.
Is there any easy way how to achieve this? My guess would be to use each() function, but to be honest, I never really got that one.
Can you unwrap my head a little bit? Thank you in advance!