function buildTree(array $elements, $parentId = 0) {
$branch = array();
foreach ($elements as $element) {
if ($element['parent_id'] == $parentId) {
$children = buildTree($elements, $element['id']);
if ($children) {
$element['children'] = $children;
}
$branch[] = $element;
}
}
return $branch;
}
$nestedCategories = buildTree($categories);
顶一下
(0)
0%
踩一下
(0)
0%
- 相关评论
- 我要评论
-