I'm trying to create nested menu via mysql and php.
When I'm creating multidimensional array from this:
$ref = [];
$items = [];
foreach($row as $row) {
$thisRef =& $ref[$row->id];
$thisRef['parent_id'] = $row->parent_id;
$thisRef['menu_id'] = $row->menu_id;
$thisRef['type'] = $row->type;
$thisRef['id'] = $row->id;
if($row->parent_id == 0) {
$items[] =& $thisRef;
} else {
$ref[$row->parent_id]['sub'][] =& $thisRef;
}
}
it generates array like this.
Array(
[0] => Array
(
[parent_id] => 0
[menu_id] => 10
[type] => p
[id] => 93
)
[1] => Array
(
[sub] => Array
(
[0] => Array
(
[parent_id] => 88
[menu_id] => 10
[type] => b
[id] => 92
[sub] => Array
(
[0] => Array
(
parent_id] => 92
[menu_id] => 8
[type] => c
[id] => 94
)
)
)
[1] => Array
(
[parent_id] => 88
[menu_id] => 8
[type] => c
[id] => 90
)
)
[parent_id] => 0
[menu_id] => 5
[type] => p
[id] => 88
)
)
)
and it's good but I'd like to change name of second array key sub I mean if array all ready has sub, second sub would be subofsub, I tried to check it with isset and array_key_exists but it just messes my array.