<?php
function recurse(&$array, $pid = null) {
foreach ($array as $id => $item) {
if (isset($item->params->data->menu_display_special) && $item->params->data->menu_display_special == 1) {
unset($array[$id]);
recurse($array, $item->id);
} elseif ($item->parent_id === $pid) {
unset($array[$id]);
}
}
}
$list = [
35 => (object)[
'id' => '2375',
'params' => (object)[
'data' => (object)[
'menu_display_special' => '1'
]
],
'parent_id' => '2376',
'parent' => false
],
36 => (object)[
'id' => '2377',
'params' => (object)[
'data' => (object)[
'menu_display_special' => '1'
]
],
'parent_id' => '2376',
'parent' => false
],
37 => (object)[
'id' => '2379',
'params' => (object)[
'data' => (object)[
'menu_display_special' => '1'
]
],
'parent_id' => '2377',
'parent' => false
],
38 => (object)[
'id' => '2380',
'params' => (object)[
'data' => (object)[
'menu_display_special' => '1'
]
],
'parent_id' => '2377',
'parent' => false
],
39 => (object)[
'id' => '2381',
'params' => (object)[
'data' => (object)[]
],
'parent_id' => '2377',
'parent' => false
],
40 => (object)[
'id' => '2378',
'params' => (object)[
'data' => (object)[]
],
'parent_id' => '2376',
'parent' => false
],
];
recurse($list);
var_export($list);
preferences:
122.04 ms | 404 KiB | 5 Q