Trip Sorter in PHP