關聯陣列根據值進行排序
阿新 • • 發佈:2018-12-15
一維關聯型資料進行排序
private function sort_with_keyName($arr,$orderby='desc'){ $new_array = array(); $new_sort = array(); foreach($arr as $key => $value){ $new_array[] = $value; } if($orderby=='asc'){ asort($new_array); }else{ arsort($new_array); } foreach($new_array as $k => $v){ foreach($arr as $key => $value){ if($v==$value){ $new_sort[$key] = $value; unset($arr[$key]); break; } } } return $new_sort; }