Good morning, given the below data structure (in JSON for ease of reading)
[
{
\"parent\": \"root\",
\"active\": \"1\",
\"label\": \"Index\",
Not very hard:
function flatten(array $array) {
$branch = [];
foreach ($array as $item) {
$children = [];
if (isset($item['children']) && is_array($item['children'])) {
$children = flatten($item['children']);
unset($item['children']);
}
$branch = array_merge($branch, [$item], $children);
}
return $branch;
}