Answer the question
In order to leave comments, you need to log in
How to limit the depth of an array when creating?
There is a Yii2 widget that generates a menu of unlimited nesting.
Tree of categories:
Array
(
[1] => Array
(
[id] => 1
[parent_id] => 0
[name] => Category 1
[children] => Array
(
[2] => Array
(
[id] => 2
[parent_id] => 1
[name] => Category 1.1
[children] => Array
(
[3] => Array
(
[id] => 3
[parent_id] => 2
[name] => Category 1.1.1
)
)
)
)
)
[4] => Array
(
[id] => 4
[parent_id] => 0
[name] => Category 2
)
)
Answer the question
In order to leave comments, you need to log in
It is possible to bypass recursively and stop at a certain depth.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question