如何按特定的子数组值对多维数组进行分组?
2022-08-30 13:54:32
我有一个多维数组,并尝试根据特定列中的值对它们进行分组。
我试图按 分组,但我实际上事先并不知道级别。所以,这并不是说我可以把它放在一个循环中并说,因为我不知道这是级别键的最大值,坦率地说,我不确定即使我这样做,我也不会这样做......level
for
while $i < 7
7
Array (
[0] => Array (
[cust] => XT8900
[type] => standard
[level] => 1
)
[1] => Array (
[cust] => XT8944
[type] => standard
[level] => 1
)
[2] => Array (
[cust] => XT8922
[type] => premier
[level] => 3
)
[3] => Array (
[cust] => XT8816
[type] => permier
[level] => 3
)
[4] => Array (
[cust] => XT7434
[type] => standard
[level] => 7
)
)
我希望生产:
Array (
[1] => Array (
[0] => Array (
[cust] => XT8900
[type] => standard
)
[1] => Array (
[cust] => XT8944
[type] => standard
)
)
[3] => Array (
[2] => Array (
[cust] => XT8922
[type] => premier
)
[3] => Array (
[cust] => XT8816
[type] => permier
)
)
[7] => Array (
[4] => Array (
[cust] => XT7434
[type] => standard
)
)
)