"how to sort date array in php?" Answer’s


Because array items is string, you need to convert them to date and then comparing to sort. The usort() sort array using custom function that is a good sort function for this case.

$arr = array('11-01-2012', '01-01-2014', '01-01-2015', '09-02-2013', '01-01-2013');    
function date_sort($a, $b) {
    return strtotime($a) - strtotime($b);
usort($arr, "date_sort");

Check result in demo

Wednesday, March 31, 2021
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :