PHP多次元配列のカスタムソート。
並べ替えは、フィールドの値に基づいて行う必要があります[position]
。人は複数のポジションを持つことができます(以下にリストされている特殊なケースを参照)。
Array
(
[0] => Array
(
[position] => Array
(
[0] => Secretary
)
)
)
配列を位置の値に基づいて並べ替えたい
- 書記長
- 大統領
- 会計
- 秘書
- 委員
以下の配列の特殊なケース では、最初の配列である必要があります。この人は「書記長」だから
[2] => Array
(
[person_id] => 51136
[position] => Array
(
[0] => General Secretary
[1] => Committee Member
)
[person_name] => Person 1
)
入力データの例
Array
(
[0] => Array
(
[person_id] => 22180
[position] => Array
(
[0] => Secretary
)
[person_name] => Person 1
)
[1] => Array
(
[person_id] => 51135
[position] => Array
(
[0] => President
)
[person_name] => Person 2
)
[2] => Array
(
[person_id] => 51136
[position] => Array
(
[0] => General Secretary
[1] => Committee Member
)
[person_name] => Person 3
)
[3] => Array
(
[person_id] => 44141
[position] => Array
(
[0] => Treasurer
)
[person_name] => Person 4
)
[4] => Array
(
[person_id] => 51137
[position] => Array
(
[0] => Committee Member
)
[person_name] => Person 5
)
)
必要な出力
Array
(
[0] => Array
(
[person_id] => 51136
[position] => Array
(
[0] => General Secretary
[1] => Committee Member
)
[person_name] => Person 3
)
[1] => Array
(
[person_id] => 51135
[position] => Array
(
[0] => President
)
[person_name] => Person 2
)
[2] => Array
(
[person_id] => 44141
[position] => Array
(
[0] => Treasurer
)
[person_name] => Person 4
)
[3] => Array
(
[person_id] => 22180
[position] => Array
(
[0] => Secretary
)
[person_name] => Person 1
)
[4] => Array
(
[person_id] => 51137
[position] => Array
(
[0] => Committee Member
)
[person_name] => Person 5
)
)