I'm trying to sort a multidimensional array down to a sorted, one-dimensional array where values on the same level are merged together ordered by key alternating between it's parents.
So start with this array:
Array
(
[0] => Array
(
[0] => Array
(
[0] => 60
[1] => 68
[2] => 71
[3] => 72
)
)
[1] => Array
(
[0] => Array
(
[0] => 61
[1] => 62
[2] => 64
)
[1] => Array
(
[0] => 69
[1] => 70
)
)
[2] => Array
(
[0] => Array
(
[0] => 63
)
[1] => Array
(
[0] => 65
[1] => 66
)
)
[3] => Array
(
[0] => Array
(
[0] => 66
)
)
)
and end up with this:
Array
(
[0] => 60
[1] => 68
[2] => 71
[3] => 72
[4] => 61
[5] => 69
[6] => 62
[7] => 70
[8] => 64
[9] => 63
[10] => 65
[11] => 66
[12] => 67
)
I tried something from this question like this:
function merge_common_keys(){
$arr = func_get_args();
$num = func_num_args();
$keys = array();
$i = 0;
for($i=0;$i<$num;++$i){
$keys = array_merge($keys, array_keys($arr[$i]));
}
$keys = array_unique($keys);
$merged = array();
foreach($keys as $key){
for($i=0;$i<$num;++$i){
if(isset($arr[$i][$key])){
$merged[] = $arr[$i][$key];
}
}
}
return $merged;
}
but it requires passing in multiple arrays and I can't figure out how to feed it just one big array and recursive walk down it.