When I run this code:
foreach ($tree as $node) {
echo str_repeat(\' \', $node->tree_depth * 4) . $node->id . PHP_EOL;
}
I get well fo
Try this code instead:
\n";
$tree = array(
array('Food', 0),
array('Fruit', 1),
array('Red', 5),
array('Cherry', 3),
array('Strawberry', 3),
array('Cool', 4),
array('Not cool', 4),
array('Yellow', 2),
array('Banana', 3),
array('Meat', 0),
array('Beef', 4),
array('Pork', 2),
);
$depth = 0;
foreach ($tree as $node) {
if ($node[1] > $depth)
echo str_repeat("\n", $node[1] - $depth);
if ($node[1] < $depth)
echo str_repeat("
\n", $depth - $node[1]);
$depth = $node[1];
echo "- " . $node[0] . "\n";
}
echo str_repeat("\n", $depth+1);
?>
I've updated it to output fewer tags, thereby reducing the number of bullets. But on the other hand, this will generate HTML that wont validate since a jump of more than one level will result in a
being generated.