/** * @param $array * @param $keys * @param string $sort * @return array */ function arraySort($array, $keys, $sort = 'asc') { $newArr = $valArr = array(); foreach ($array as $key => $value) { $valArr[$key] = $value[$keys]; } ($sort == 'asc') ? asort($valArr) : arsort($valArr); reset($valArr); foreach ($valArr as $key => $value) { $newArr[$key] = $array[$key]; } return $newArr; }
因爲排序後的二位數組索引不是連續的,而後能夠重置索引:數組
1.array_values()spa
2.array_merge()code
3.循環遍歷數組到一個新數組中。blog
function resetArr($arr){ $temp = array(); foreach($arr as $v){ $temp[] = $v; } return $temp; }