[php] multi-dimensional array sort


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.