usort()使用方法:

$users = array(
	array('name' => 'tom', 'age' => 20)
	, array('name' => 'anny', 'age' => 18)
	, array('name' => 'jack', 'age' => 22)
);
	
usort($users, function($a, $b) { //回调函数排序,在回调函数里面可以做任何事,很方便
	$al = $a['age'];
	$bl = $b['age'];
	if ($al == $bl)
		return 0;
	return ($al > $bl) ? 1 : -1;
});



array_multisort()

$ages = array();
foreach ($users as $user) {
	$ages[] = $user['age'];
}
// $users 要排序的二维数组
// $ages 要排序的字段,必须提取出来,
array_multisort($ages, SORT_ASC, $users);


print_r($users);






本例中将把 volume 降序排列,把 edition 升序排列。

<?php
// 取得列的列表
foreach ($data as $key => $row) {
    $volume[$key]  = $row['volume'];
    $edition[$key] = $row['edition'];
}

// 将数据根据 volume 降序排列,根据 edition 升序排列
// 把 $data 作为最后一个参数,以通用键排序
array_multisort($volume, SORT_DESC, $edition, SORT_ASC, $data);
?>

类似于sql语句中的 order by ages asc




其他参考资料

http://php.net/manual/zh/function.array-multisort.php