php – Sort array of dates

Your date format is Y-m-d which means that you can safely sort these values as simple strings.

rsort() is all that you require. A native function will always be more concise and efficient than a custom (non-native) function.

If your date string were not zero-padded or the date units were not arranged with descending unit values, then additional work would be required.

If the date format was, say, d.m.Y, then strtotime() would standardize/stabilize the values.

usort(fn($a, $b) => strtotime($b) <=> strtotime($a), $GoodDates);