1 回答

TA貢獻(xiàn)1869條經(jīng)驗(yàn) 獲得超4個(gè)贊
根據(jù)您的示例,您實(shí)際上是在嘗試areas對(duì)子數(shù)組進(jìn)行排序,而不是對(duì)整個(gè)父數(shù)組進(jìn)行排序。因此,您需要依次循環(huán)每個(gè)子數(shù)組并分別對(duì)它們進(jìn)行排序。
$array = [
'chicago' => [
'community_name' => 'Chicago, IL',
'areas' => [
[
'name' => ['HELLO WORLD.']
],
[
'name' => ['Hello'],
],
[
'name' => ['Administration.'],
],
],
],
'chicago-and-surrounding-areas' => [
'community_name' => 'Chicago (and surrounding areas), IL',
'areas' => [
[
'name' => ['Carry.']
],
[
'name' => ['Bacteria.'],
],
],
],
'cambridge-chicago' => [
'community_name' => 'Cambridge (Chicago), IL',
'areas' => [
[
'name' => ['Responsibility.']
],
[
'name' => ['Bacteria'],
],
],
],
];
foreach ($array as &$locality) {
usort($locality['areas'], function ($a, $b) {
return $a['name'][0] <=> $b['name'][0];
});
}
var_dump($array);
- 1 回答
- 0 關(guān)注
- 134 瀏覽
添加回答
舉報(bào)