时间:2021-07-01 10:21:17 帮助过:28人阅读
$arr = array(
array('id' => 1,'name' => 'aaa','uid'=>1),
array('id' => 2,'name' => 'bbb','uid'=>2),
array('id' => 3,'name' => 'ccc','uid'=>3),
array('id' => 4,'name' => 'ddd','uid'=>4),
array('id' => 5,'name' => 'ccc','uid'=>4),
array('id' => 6,'name' => 'bbb','uid'=>4),
array('id' => 7,'name' => 'bbb','uid'=>5),
array('id' => 8,'name' => 'fff','uid'=>6),
array('id' => 9,'name' => 'ccc','uid'=>7),
array('id' => 10,'name' => 'bbb','uid'=>8),
array('id' => 11,'name' => 'ddd','uid'=>8),
array('id' => 12,'name' => 'eee','uid'=>9),
array('id' => 13,'name' => 'fff','uid'=>10),
);
usort($arr, function($a, $b) {
if($a['uid'] == $b['uid']) return rand(-1, 1);
return $a['uid'] > $b['uid'] ? 1 : -1;
});
print_r($arr);