How order an array so structured for [name] and to parity of [name] for [age] ?
[0] => Array
(
[name] => Mary
[age] => 32
)
[1] => Array
(
[name] => Mary
[age] => 31
)
[2] => Array
(
[name] => Anna
[age] => 30
)
Output:
Name | Age
----------
Anna | 30
Mary | 31
Mary | 32
這是代碼:如何訂購多維數組的多維數組?
function sort(&$array) {
function build_sorter($key) {
return function ($a, $b) use ($key) {
return strnatcmp($a[$key], $b[$key]);
};
}
usort($array, build_sorter(["name"]));
usort($array, build_sorter(["age"]));
}
請再具體些,並顯示您的預計產量。此外,顯示迄今爲止嘗試的代碼。 –
你可以粘貼你的代碼嗎? –
你想按名稱和年齡對數組進行排序? –