慕尼黑的夜晚无繁华
这是解决方案:$source_array = array(10 => '06:30pm', 20 => '04:00pm', 30 => '05:15pm', 40 => '04:00am');function arr_swap_elements(&$arr, $a_index, $b_index) { $tmp = $arr[$a_index]; $arr[$a_index] = $arr[$b_index]; $arr[$b_index] = $tmp; return;}function arr_sort_by_time(&$source_array, $start_index = 0, $arr_keys = null, $arr_len = null) { if (is_null($arr_keys)) { $arr_keys = array_keys($source_array); } if (is_null($arr_len)) { $arr_len = count($source_array); } for ($i = $start_index; $i < $arr_len; $i++) { if ($i > 0) { if (strtotime($source_array[$arr_keys[$i]]) > strtotime($source_array[$arr_keys[$i - 1]])) { $was_swapped = true; arr_swap_elements($source_array, $arr_keys[$i], $arr_keys[$i - 1]); } } } if ($start_index + 1 < $arr_len) { arr_sort_by_time($source_array, $start_index + 1, $arr_keys, $arr_len); }}arr_sort_by_time($source_array);var_dump($source_array);