<php学习>最简单、常用的多维数组排序

692 查看

$users = array(
   array('time' => 1398869665, 'name' => 'Jenny', 'age' => 20 ),
   array('time' => 1398854528, 'name' => 'Ben', 'age' => 22),
   array('time' => 1398854536, 'name' => 'Anna', 'age' => 18 ),
   array('time' => 1398869401, 'name' => 'Bob', 'age' => 25 ),
);

$time = array();

foreach($users $key => $user)
{
    $time[$key] = $user['time'];
}

array_multisort($time, SORT_DESC,  $users);

关联(string)键名保持不变,但数字键名会被重新索引。

排序顺序标志:
1.SORT_ASC - 按照上升顺序排序
2.SORT_DESC - 按照下降顺序排序