php实现多维数组排序的方法示例
讲述了php实现多维数组排序的方法。分享给大家供大家参考,具体如下:
- //定义一个学生数组
- $students = array(
- 256=>array('name'=>'jon','grade'=>98.5),
- 2=>array('name'=>'vance','grade'=>85.1),
- 9=>array('name'=>'stephen','grade'=>94.0),
- 364=>array('name'=>'steve','grade'=>85.1),
- 68=>array('name'=>'rob','grade'=>74.6),
- );
- //按照名称进行排序
- function name_sort($x, $y)
- {
- return strcasecmp($x['name'],$y['name']);
- }
- //按照成绩进行排序
- function grade_sort($x,$y)
- {
- return ($x['grade'] > $y['grade']);
- }
- //应用
- uasort($students, name_sort);
- uasort($students, grade_sort);