How can PHP be used to sort data in ascending or descending order based on dates?

To sort data in ascending or descending order based on dates in PHP, you can use the `usort()` function along with a custom comparison function that compares the dates. The comparison function should convert the dates to timestamps using `strtotime()` and then compare them to determine the sorting order.

// Sample array of dates
$dates = ['2022-01-15', '2021-12-25', '2022-02-10'];

// Custom comparison function for sorting dates in ascending order
function compareDatesAsc($a, $b) {
    return strtotime($a) - strtotime($b);
}

// Custom comparison function for sorting dates in descending order
function compareDatesDesc($a, $b) {
    return strtotime($b) - strtotime($a);
}

// Sort dates in ascending order
usort($dates, 'compareDatesAsc');
print_r($dates);

// Sort dates in descending order
usort($dates, 'compareDatesDesc');
print_r($dates);