我有一个数组,我需要在一个多级数组中对该数组进行排序。我正在尝试按其字段对其进行分组,但我可以使其工作。这是我拥有的数组的示例以及我想要的
Array
(
[0] => Array
(
[id] => sports
[title] => this is sports
)
[1] => Array
(
[id] => cricket
[title] => this is cricket
[under] => sports
)
[2] => Array
(
[id] => batsman
[title] => this is batsman
[under] => cricket
)
[3] => Array
(
[id] => sachin
[title] => this is sachin
[under] => batsman
)
[4] => Array
(
[id] => football
[title] => this is football
[under] => sports
)
[5] => Array
(
[id] => ronaldo
[title] => this is ronaldo
[under] => football
)
)
我需要对这个数组进行分组并使它像这样
Array(
[0] => Array(
[id] => Array(
[sports] => Array(
[cricket] => Array(
[batsman] => sachin
)
[football] => fun
)
)
)
)
我试过这样的东西,但它不工作
foreach($my_array as $item) {
//group them by under
$my_grouped_array[$item['under']][] = $item;
}
任何建议都会很棒。