如何使用<=>
(宇宙飞船运营商)重写此uasort($hits, function($a, $b) {
if($a['total'] == $b['total']) {
if($a['vat'] == $b['vat']) {
return 0;
} else {
return ($a['vat'] > $b['vat']) ? -1 : 1;
}
} else {
return ($a['total'] > $b['total']) ? -1 : 1;
}
}
功能?
FlatFileItemReader
答案 0 :(得分:3)
return $b['total'] <=> $a['total'] ?: $b['vat'] <=> $a['vat'];
如果总数相等,<=>
会返回0
,这是假的,因此?:
运算符将返回大桶比较的结果。将返回第一个非0结果。
答案 1 :(得分:3)
像
这样的东西uasort($hits, function($a, $b){
return [$b['total'], $b['vat']] <=> [$a['total'], $a['vat']];
});
答案 2 :(得分:0)
那应该有用
uasort($hits, function($a, $b){
if($a['total'] == $b['total']){
return ($b['vat'] <=> $a['vat']);
}
else{
return ($b['total'] <=> $a['total']);
}
});