I
I
Ivan Petrov2016-09-10 20:42:33
PHP
Ivan Petrov, 2016-09-10 20:42:33

How to recurse a multi-level menu from an array?

There is an array of this kind.
How to display a multi-level menu with a recursive function? I tried to figure it out, but I don't understand how to implement it.

$cat = [
    ['id' => 1, 'parentid' => 0, 'name' => 'programming languages'],
    ['id' => 3, 'parentid' => 1, 'name' => 'php'],
    ['id' => 4, 'parentid' => 1, 'name' => 'javascript'],
    ['id' => 7, 'parentid' => 4, 'name' => 'jquery'],
    ['id' => 8, 'parentid' => 1, 'name' => 'jqueryUI'],
    ['id' => 10, 'parentid' => 8, 'name' => 'datePicker'],
    ['id' => 11, 'parentid' => 10, 'name' => 'time'],
    ['id' => 12, 'parentid' => 10, 'name' => 'date'],
    ['id' => 13, 'parentid' => 1, 'name' => 'ruby'],
];

Answer the question

In order to leave comments, you need to log in

3 answer(s)
I
index0h, 2016-09-10
@index0h

Google search phrase: "php recursive menu"

D
dev400, 2016-09-11
@dev400

nested sets
https://habrahabr.ru/post/153861/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question