这是我的数组输出
Array
(
[1] => Array
(
[id] => 1
[name] => Category A
[parent] => 0
)
[2] => Array
(
[id] => 2
[name] => Sub Cat A - 1
[parent] => 1
)
[3] => Array
(
[id] => 3
[name] => Sub Cat A - 2
[parent] => 1
)
[4] => Array
(
[id] => 4
[name] => Sub Cat A 2 - 1
[parent] => 3
)
[5] => Array
(
[id] => 5
[name] => Category B
[parent] => 0
)
[6] => Array
(
[id] => 6
[name] => Sub Cat B - 1
[parent] => 5
)
[7] => Array
(
[id] => 7
[name] => Category C
[parent] => 0
)
)
我尝试过这个但输出错误。
foreach ($categories as $key => $category) {
$group[$category['parent']][$key] = $category;
}
问题:如何重新组合数组&我的期望输出应该是这样的
Category A
Sub Cat A - 1
Sub Cat A - 2
Sub Cat A 2 - 1
Category B
Sub Cat B - 1
Category C