二維數組排序

/*$arr 數組 * $name 排序依據列 * $asc asc正序 desc 倒序 * */function arr_sort($arr,$name,$type='asc'){    $temp=array();    foreach($arr as $v){        $temp[$v[$name]]=$v;    }    if($type=='asc'){        ksort($temp);    }else{        krsort($temp);    }    return $temp;}$attr2=array(    array("id"=>1,"name"=>"liming","age"=>21),    array("id"=>3,"name"=>"daten","age"=>27),    array("id"=>2,"name"=>"xiaohua","age"=>18),);echo "<pre>";var_dump(arr_sort($attr2,"age"));
相關文章
相關標籤/搜索