<?php
function recusive_list($items, $c) {
$c += 1;
$text = '';
foreach ($items as $key => $item) {
$text .= str_repeat('*', $c) . ' ' .$key. ' - ' .$item. "\n"; else
$text .= recusive_list($item, $c);
}
return $text;
}
$items = [
[
'href' => 'www.item1',
'name' => 'Item1',
'childs' => [
[
'href' => 'www.item1.1',
'name' => 'Item1.1',
'childs' => []
]
]
],
[
'href' => 'www.item2',
'name' => 'Item2',
'childs' => [
[
'href' => 'www.item2.1',
'name' => 'Item2.1',
'childs' => [
[
'href' => 'www.item2.1.1',
'name' => 'Item2.1.1',
'childs' => []
],
[
'href' => 'www.item2.1.2',
'name' => 'Item2.1.2',
'childs' => [
[
'href' => 'www.item2.1.2.1',
'name' => 'Item2.1.2.1',
'childs' => []
]
]
]
]
]
]
],
[
'href' => 'www.item3',
'name' => 'Item3',
'childs' => []
],
];
echo recusive_list($items, 0);
PD9waHAKCmZ1bmN0aW9uIHJlY3VzaXZlX2xpc3QoJGl0ZW1zLCAkYykgewogICAgJGMgKz0gMTsKICAgICR0ZXh0ID0gJyc7CiAgICBpZiAoaXNfb2JqZWN0KCRpdGVtcykpCiAgICAgICAgJGl0ZW1zID0gZ2V0X29iamVjdF92YXJzKCRpdGVtcyk7CiAgICBmb3JlYWNoICgkaXRlbXMgYXMgJGtleSA9PiAkaXRlbSkgewogICAgICAgIGlmKCFpc19hcnJheSgkaXRlbSkpCiAgICAgICAgICAgICR0ZXh0IC49IHN0cl9yZXBlYXQoJyonLCAkYykgLiAnICcgLiRrZXkuICcgLSAnIC4kaXRlbS4gIlxuIjsKICAgICAgICBlbHNlCiAgICAgICAgICAgICR0ZXh0IC49IHJlY3VzaXZlX2xpc3QoJGl0ZW0sICRjKTsKICAgIH0KICAgIHJldHVybiAkdGV4dDsKfQoKJGl0ZW1zID0gWwogICAgWwogICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0xJywKICAgICAgICAnbmFtZScgPT4gJ0l0ZW0xJywKICAgICAgICAnY2hpbGRzJyA9PiBbCiAgICAgICAgICAgIFsKICAgICAgICAgICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0xLjEnLAogICAgICAgICAgICAgICAgJ25hbWUnID0+ICdJdGVtMS4xJywKICAgICAgICAgICAgICAgICdjaGlsZHMnID0+IFtdCiAgICAgICAgICAgIF0KICAgICAgICBdCiAgICBdLAogICAgWwogICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0yJywKICAgICAgICAnbmFtZScgPT4gJ0l0ZW0yJywKICAgICAgICAnY2hpbGRzJyA9PiBbCiAgICAgICAgICAgIFsKICAgICAgICAgICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0yLjEnLAogICAgICAgICAgICAgICAgJ25hbWUnID0+ICdJdGVtMi4xJywKICAgICAgICAgICAgICAgICdjaGlsZHMnID0+IFsKICAgICAgICAgICAgICAgICAgICBbCiAgICAgICAgICAgICAgICAgICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0yLjEuMScsCiAgICAgICAgICAgICAgICAgICAgICAgICduYW1lJyA9PiAnSXRlbTIuMS4xJywKICAgICAgICAgICAgICAgICAgICAgICAgJ2NoaWxkcycgPT4gW10KICAgICAgICAgICAgICAgICAgICBdLAogICAgICAgICAgICAgICAgICAgIFsKICAgICAgICAgICAgICAgICAgICAgICAgJ2hyZWYnID0+ICd3d3cuaXRlbTIuMS4yJywKICAgICAgICAgICAgICAgICAgICAgICAgJ25hbWUnID0+ICdJdGVtMi4xLjInLAogICAgICAgICAgICAgICAgICAgICAgICAnY2hpbGRzJyA9PiBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBbCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgJ2hyZWYnID0+ICd3d3cuaXRlbTIuMS4yLjEnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICduYW1lJyA9PiAnSXRlbTIuMS4yLjEnLAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICdjaGlsZHMnID0+IFtdCiAgICAgICAgICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICAgICAgICAgICAgICAgIF0KICAgICAgICAgICAgICAgICAgICBdCiAgICAgICAgICAgICAgICBdCiAgICAgICAgICAgIF0KICAgICAgICBdCiAgICBdLAogICAgWwogICAgICAgICdocmVmJyA9PiAnd3d3Lml0ZW0zJywKICAgICAgICAnbmFtZScgPT4gJ0l0ZW0zJywKICAgICAgICAnY2hpbGRzJyA9PiBbXQogICAgXSwKXTsKCmVjaG8gcmVjdXNpdmVfbGlzdCgkaXRlbXMsIDApOw==