【发布时间】:2009-05-23 13:58:14
【问题描述】:
当我运行这段代码时:
foreach ($tree as $node) {
echo str_repeat(' ', $node->tree_depth * 4) . $node->id . PHP_EOL;
}
我得到格式良好的文本,例如:
Food
Fruit
Red
Cherry
Strawberry
Cool
Not cool
Yellow
Banana
Meat
Beef
Pork
但我想用<ul><li>...创建一个列表:
我试过了:
echo '<ul>';
$prev_depth = 0;
foreach($table->fetchTree() as $row) {
if ($row->tree_depth > $prev_depth) {
echo '<li><ul>';
} else if ($row->tree_depth < $prev_depth) {
echo '</li></ul>';
}
echo '<li>' . $row->name . '</li>';
$prev_depth = $row->tree_depth;
}
echo '</ul>';
但是我有一些额外的 ul 标签等等。我为此浪费了 2 天,所以如果你能帮助我,请在此处发布...
【问题讨论】:
-
我们可能需要一个小数据集。