Posted By

wanchun0222 on 10/14/11


Tagged

sort array


Versions (?)

[php] multi-dimensional array sort


 / Published in: PHP
 

URL: http://www.coderbolg.com/content/144.html

  1. $arr = array(
  2.  
  3. 'index'=>array( 'name'=>'首页','order'=>3),
  4.  
  5. 'intro'=>array( 'name'=>'企业概况','order'=>2),
  6.  
  7. 'news'=>array( 'name'=>'新闻动态','order'=>1 ),
  8.  
  9. 'product'=>array( 'name'=>'产品中心','order'=>4 ),
  10.  
  11. 'message'=>array( 'name'=>'访客留言','order'=>7 ),
  12.  
  13. 'position'=>array( 'name'=>'人才招聘','order'=>6),
  14.  
  15. 'contact'=>array( 'name'=>'联系我们','order'=> 5 )
  16.  
  17. );
  18.  
  19. uasort($arr, 'cmp');
  20.  
  21. public function cmp($a, $b){
  22.  
  23. return $a['order'] - $b['order'];
  24.  
  25. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wanchun0222 on October 14, 2011

oh, callback function very nice!

You need to login to post a comment.