There is a one-dimensional array. The ascending order is configured. How to make a ul tree type nested list?
That is, the most important parent is transport, then a child of passenger cars and the last child is mercedes
Perhaps the author wants something like this:
$a = [ 0 => [ 'title' => 'Транспорт', 'values' => [ 0 => [ 'title' => 'Легковые', 'values' => [ 0 => ['title' => 'car1'], 1 => ['title' => 'car2'], ], ], ], ] ]; function echoUl($tree) { echo "<ul>" foreach ($tree as $value) { echo "<li>"; echo "<b>" . $value['title'] . "</b><br/>"; if (isset($value['values'])) { echoUl($value['values']); } echo "</li>"; } echo "</ul>"; } echoUl($a); I assume that a one-dimensional array should be converted into a tree.
$a = [ 'transport', 'cars', 'mers' ]; foreach( $a as $b ) { echo "<ul><li>$b"; } $i = count($a); while( $i-- ) { echo '</li></ul>'; } But something tells me that it is not really necessary.
Source: https://ru.stackoverflow.com/questions/536057/
All Articles
[3] => Транспорт,[4] => Грузовые авто,[5] => Камаз, and so on, three each? And the array is long, and its task is to run through it all, and disassemble it into a tree, where in the root “Transport” will be only once? - Sergiks