How to sort an array of times chronologically?

前端 未结 8 924
梦毁少年i
梦毁少年i 2021-01-17 18:39

I have a non-associative array where the data that comes in is not sorted (I\'m receiving the data from an outside system and cannot force it to come into the array in sorte

8条回答
  •  再見小時候
    2021-01-17 19:38

    sort, like all of php's sorting functions, sorts in-place. It returns true if the sorting was successful, false otherwise. This result is irrelevant if you're only sorting strings/numbers.

    $wedTrackTimes = array("9:30 AM-10:30 AM", "8:15 AM-9:15 AM",
                           "12:30 PM-1:30 PM", "2:00 PM-3:00 PM", "3:30 PM-4:30 PM");
    $wedTrackTimes = array_unique($wedTrackTimes);
    sort($wedTrackTimes);
    print_r($wedTrackTimes);
    

    is the way to go.

提交回复
热议问题