Armstuff > xxxxx
Uncategorized
Biler > test
HOVED > SUB
Computere > Software
Smykker
Computere > Komponenter > RAM
sss > bbb > kkk
Computere > Komponenter > Harddiske
gg
Computere > Gadgets
Biler > Ekstraudstyr
sss > ddd
这是我的类别列表,由以下代码输出:
<?php
foreach($categories as $category)
{
echo $category['name'] . " <br />";
}
?>
现在 $categories 子类别名称被正确定义,之前在代码中通过:
foreach($categories as &$category)
{
$parent = $category['parent'];
while($parent > 0)
{
$parent_row = $db->select('name', 'paraent')->from('categories')->where('id', '=', $parent)->execute()->as_array();
$parent_row = $parent_row[0];
$category['name'] = $parent_row['name'] . " > {$category['name']}";
$parent = $parent_row['parent'];
}
}
我希望输出按字母顺序输出,因此从上面的示例中,它应该输出如下内容:
Armstuff > xxxxx
Biler > test
Biler > Ekstraudstyr
Computere > Gadgets
Computere > Komponenter > Harddiske
Computere > Komponenter > RAM
Computere > Software
gg
HOVED > SUB
Smykker
sss > bbb > kkk
sss > ddd
Uncategorized
我尝试了简单的 sort()、asort(),但它们不适合我。我怎样才能做到这一点?谢谢转发