我有一个像这样的数组
[Defense] => Array
(
[0] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.6
)
[1] => stdClass Object
(
[id] => 1
[position] => F
[point] => 2.7
)
[2] => stdClass Object
(
[id] => 1
[position] => C
[point] => 1.4
)
[3] => stdClass Object
(
[id] => 2
[position] => C
[point] => 1.7
)
[4] => stdClass Object
(
[id] => 2
[position] => D
[point] => 1.1
)
[5] => stdClass Object
(
[id] => 1
[position] => F
[point] => 1.7
)
[6] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.6
)
[7] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.8
)
[8] => stdClass Object
(
[id] => 2
[position] => D
[point] => 1.5
)
)
我想根据descending
中的PHP
点对数组进行排序。此外,所有位置都按顺序排列(所有G
都比F
所有......所以......)
像这样:
[Defense] => Array
(
[0] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.8
)
[1] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.6
)
[2] => stdClass Object
(
[id] => 1
[position] => G
[point] => 1.6
)
[3] => stdClass Object
(
[id] => 1
[position] => F
[point] => 2.7
)
[4] => stdClass Object
(
[id] => 1
[position] => F
[point] => 1.7
)
[5] => stdClass Object
(
[id] => 1
[position] => C
[point] => 1.7
)
[6] => stdClass Object
(
[id] => 2
[position] => C
[point] => 1.4
)
[7] => stdClass Object
(
[id] => 2
[position] => D
[point] => 1.5
)
[8] => stdClass Object
(
[id] => 2
[position] => D
[point] => 1.1
)
)
任何帮助?
答案 0 :(得分:1)
使用usort()函数对数组进行排序,如下所示
usort($array,function($a,$b){
if($a->position == $b->position )
return $a->point < $b->point;
else
return $a->position < $b->position;
});
var_dump($array);