How can arrays be sorted in PHP based on custom criteria?

To sort arrays in PHP based on custom criteria, you can use the `usort()` function along with a custom comparison function. The custom comparison function should define the criteria for sorting the array elements. This allows you to sort the array based on any custom logic you require.

// Sample array to be sorted based on custom criteria
$numbers = [5, 2, 8, 1, 9];

// Custom comparison function to sort numbers in descending order
function customSort($a, $b) {
    if ($a == $b) {
        return 0;
    }
    return ($a > $b) ? -1 : 1;
}

// Sort the array using the custom comparison function
usort($numbers, 'customSort');

// Output the sorted array
print_r($numbers);