码迷,mamicode.com
首页 > 编程语言 > 详细

php 多维(三)数组指定字段排序

时间:2018-01-17 00:11:42      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:oms   gty   multisort   pre   指定字段   例子   typeid   int   als   

例子:

<?php 
    $arr = array(
      0=>
      array(
        "id"=>"1208",
        "fromid"=>"2",
        "froms"=>"strategy",
        "name"=>"",
        "sort"=>"1"
      ),
      1=>
      array(
        "id"=>"1209",
        "fromid"=>"3",
        "froms"=>"strategy",
        "name"=>"",
        "sort"=>"7"
      ),
      2=>
      array(
        "id"=>"1210",
        "fromid"=>"271",
        "froms"=>"tag",
        "name"=>"BC",
        "sort"=>"2"
      ),
      3=>
      array (
        "id"=>"1211",
        "fromid"=>"263",
        "froms"=>"tag",
        "name"=>"777",
        "sort"=>"3"
      ),
      4=>
      array (
        "id"=>"1212",
        "fromid"=>"262",
        "froms"=>"tag",
        "name"=>"6666",
        "sort"=>"5"
      ),
      5=>
      array (
        "choosecardtypeid"=>"1",
        "fromid"=>"114",
        "froms"=>"tagtype",
        "sort"=>"4",
        "name"=>"你还打算的"
      ),
      6=>
      array (
        "choosecardtypeid"=>"1",
        "fromid"=>"115",
       "froms"=>"tagtype",
        "sort"=>"6",
        "name"=> "呵呵呵"
      )
    );
    
function multi_array_sort($multi_array,$sort_key,$sort=SORT_ASC){ 
    if(is_array($multi_array)){ 
        foreach ($multi_array as $row_array){ 
            if(is_array($row_array)){ 
                $key_array[] = $row_array[$sort_key]; 
            }else{ 
                return false; 
            } 
        } 
    }else{ 
        return false; 
    } 
    array_multisort($key_array,$sort,$multi_array); 
    return $multi_array; 
} 
    
    print_r(multi_array_sort($arr,‘sort‘));

php 多维(三)数组指定字段排序

标签:oms   gty   multisort   pre   指定字段   例子   typeid   int   als   

原文地址:https://www.cnblogs.com/richardcastle/p/8297355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!