1 php arrays sorting multidimensional-array
我有一个数组,示例:
$array {
[0] {
[something]=1;
[something2]=2;
}
[1] {
[something]=2;
[something2]=4;
}
[2] {
[something]=5;
[something2]=2;
}
}
Run Code Online (Sandbox Code Playgroud)
我想根据关键字订购数组;
所以它看起来像:
$array {
[0] {
[something]=5;
[something2]=2;
}
[1] {
[something]=2;
[something2]=4;
}
[2] {
[something]=1;
[something2]=2;
}
}
Run Code Online (Sandbox Code Playgroud)
function compare($x, $y) {
return $x['something'] - $y['something'];
}
usort($input_array, 'compare');
Run Code Online (Sandbox Code Playgroud)
你需要使用usort()
类似于上面的.