php陣列排序函式

2022-07-19 22:12:32 字數 2274 閱讀 7126

$data=array(

'team'=>$item['post_name'],

'name'=>$item['name'],

'total'=>$total,

'total_point'=>$total_pt,

'total_hd'=>$total_hd,

'chousale'=>$chousale,

'chousale_pt'=>$chousale_pt,

'chousale_hd'=>$chousale_hd,

);$data = syssortarray($data,'total_point','sort_desc','sort_numeric');

function syssortarray($arraydata,$keyname1,$sortorder1 = "sort_asc",$sorttype1 = "sort_regular")

$argcount = func_num_args();

for($i = 1;$i < $argcount;$i ++)

else

}foreach($arraydata as $key => $info)

[$key] = $info[$keyname];

}} $evalstring = 'array_multisort('.join(",",$sortrule).',$arraydata);';

eval ($evalstring);

return $arraydata;

}

用php自帶array_multisort函式排序

$data = array();

$data = array('volume' => 67, 'edition' => 2);

$data = array('volume' => 86, 'edition' => 1);

$data = array('volume' => 85, 'edition' => 6);

$data = array('volume' => 98, 'edition' => 2);

$data = array('volume' => 86, 'edition' => 6);

$data = array('volume' => 67, 'edition' => 7);

// 取得列的列表

foreach ($data as $key => $row)

array_multisort($volume, sort_desc, $edition, sort_asc, $data);

print_r($data);

自定義函式排序1

$data = array();

$data = array('volume' => 67, 'edition' => 2);

$data = array('volume' => 86, 'edition' => 1);

$data = array('volume' => 85, 'edition' => 6);

$data = array('volume' => 98, 'edition' => 2);

$data = array('volume' => 86, 'edition' => 6);

$data = array('volume' => 67, 'edition' => 7);

// 取得列的列表

foreach ($data as $key => $row)

$ret = arraysort($data, 'volume', 'desc');

print_r($ret);

/*** @desc arraysort php二維陣列排序 按照指定的key 對陣列進行排序

* @param array $arr 將要排序的陣列

* @param string $keys 指定排序的key

* @param string $type 排序型別 asc | desc

* @return array

*/function arraysort($arr, $keys, $type = 'asc')

$type == 'asc' ? asort($keysvalue) : arsort($keysvalue);

reset($keysvalue);

foreach ($keysvalue as $k => $v)

return $new_array;

}

PHP陣列排序函式

array multisort 對多個陣列或多維陣列進行排序,可以一次對多個陣列進行排序,或者根據一維或多維對多維陣列進行排序。排序後字串鍵名保持不變,數字鍵名會被重新索引。第乙個引數為要排序的陣列,第二引數為排序順序標識,預設為sort asc,第三個引數為排序型別標識,預設為sort regul...

PHP陣列排序函式 ksort krsort

bool krsort array array int sort flags 對陣列按照鍵名逆向排序,保留鍵名到資料的關聯。主要用於結合陣列。如果成功則返回true,失敗則返回false。例 fruits array d lemon a orange b banana c krsort fruits...

PHP陣列的排序函式

介紹 sort 按照字母或數字公升序對陣列中的元素進行排序,rsort作用則相反 char array b a d sort cars numbers array 3,5,1,22,11 sort numbers asort 根據值對關聯陣列進行公升序排序,arsort作用相反 age array ...