How can a custom sorting function be implemented in PHP to sort arrays based on specific keys?

To implement a custom sorting function in PHP to sort arrays based on specific keys, you can use the `usort()` function along with a custom comparison function. This comparison function should compare the specific keys of the array elements to determine their order.

// Sample array to be sorted based on 'name' key
$people = [
    ['name' => 'Alice', 'age' => 30],
    ['name' => 'Bob', 'age' => 25],
    ['name' => 'Charlie', 'age' => 35]
];

// Custom comparison function to sort by 'name' key
function customSort($a, $b) {
    return strcmp($a['name'], $b['name']);
}

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

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