I have some problems with parent array that contains multiple children array. It will be necessary that the array children, does not contain themselves other children array, but if it is the case, then to raise these array grandchildren at the level of children.
[0] => Array (
[0] => Array (
[name] => ...
[count] => ...
[url] => ...
[html] => ...
)
[1] => Array (
[name] => ...
[count] => ...
[url] => ...
)
[2] => Array (
[1] => Array (
[name] => ...
[count] => ...
[url] => ...
[html] => ...
)
[2] => Array (
[name] => ...
[count] => ...
[url] => ...
)
)
[3] => Array (
[name] => ...
[count] => ...
[url] => ...
)
[4] => Array (
[name] => ...
[count] => ...
[url] => ...
)
);
In the example array["2"]
contain 2 array, I want that the 2 array go up one level and so become brothers and not children.
Can you help me please with the right function ?
function transformMultipleArraysTo1(array $multipleArrays = null)
{
$newArray = array();
if (!isArrayEmpty($multipleArrays)) {
foreach ($multipleArrays as $array) {
if (is_array($array)) {
foreach ($array as $singleArray) {
if (is_array($singleArray)) {
$newArray[] = $singleArray;
} else {
continue 2;
}
}
$newArray[] = $array;
}
}
}
return $newArray;
}
Many thanks