1、sql查詢排序參數是order by,那么php進行排序呢
可以參考array_multisrot函數
//php進行二維數組排序 -xzz1009 foreach($home as $home){ $ages[] = $home['s_id']; } $home = array_multisort($ages, SORT_DESC, $home); //end
var_dump($home)即可查看。
2、如果想實現多個字段排序,即s_id倒序、age正序,可以參考下面代碼:
foreach($home as $home){ $s_ids[] = $home['s_id']; $ages[] = $home['age']; } $home =array_multisort($s_ids, SORT_DESC, $ages, SORT_ASC, $home); //var_dump($home);
3、其中,以s_id是二維數組里面的一維數組索引。