php 多维数组排序

WBOY
Release: 2016-06-20 12:54:58
Original
1009 people have browsed it


//定义一个学生数组

$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);



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!