array_column() 和 array_multisort() 搭配使用
<?php
$data = array(
array(
'id' => 5698,
'first_name' => 'Bill',
'add_time' => 1234,
),
array(
'id' => 4767,
'first_name' => 'Steve',
'add_time' => 1233,
),
array(
'id' => 3809,
'first_name' => 'Mark',
'add_time' => 1239,
)
);
$add_time = array_column($data,'add_time');
array_multisort($add_time,SORT_ASC,$data);
var_dump($data);
?>
输出结果:
array(3) {
[0]=>
array(3) {
["id"]=>
int(4767)
["first_name"]=>
string(5) "Steve"
["last_time"]=>
int(1233)
}
[1]=>
array(3) {
["id"]=>
int(5698)
["first_name"]=>
string(4) "Bill"
["last_time"]=>
int(1234)
}
[2]=>
array(3) {
["id"]=>
int(3809)
["first_name"]=>
string(4) "Mark"
["last_time"]=>
int(1239)
}
}
|