Home > php教程 > php手册 > php中多维数组按指定value排序的实现代码

php中多维数组按指定value排序的实现代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:19:19
Original
1393 people have browsed it

这篇文章主要介绍了php中多维数组按指定value排序的实现代码,可以实现类似数据库排序字段的排序效果,需要的朋友可以参考下

呵呵,业务需要按多维数组中某个元素进行排序,,在PHP中也是非常容易实现的,一个函数调用一个回调函数就搞定了。贴出代码:

复制代码 代码如下:


$arr = array(   

    'index'=>array( 'name'=>'首页','order'=>3),

    'intro'=>array( 'name'=>'企业概况','order'=>2),

    'news'=>array( 'name'=>'新闻动态','order'=>1 ),

    'product'=>array( 'name'=>'产品中心','order'=>4 ),

    'message'=>array( 'name'=>'访客留言','order'=>7 ),

    'position'=>array( 'name'=>'人才招聘','order'=>6),

    'contact'=>array( 'name'=>'联系我们','order'=> 5 )

);

uasort($arr, 'cmp');

public function cmp($a, $b){

   return $a['order'] - $b['order'];

}


这时$arr就是以order大小排序了,呵呵……
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template