How can multidimensional arrays be sorted in PHP based on both content and keys?

When sorting multidimensional arrays in PHP based on both content and keys, you can use the uasort() function along with a custom comparison function. This allows you to define your own sorting logic that considers both the values and keys of the array elements.

// Sample multidimensional array
$multiArray = array(
    'key1' => array('name' => 'John', 'age' => 30),
    'key2' => array('name' => 'Alice', 'age' => 25),
    'key3' => array('name' => 'Bob', 'age' => 35)
);

// Custom comparison function for uasort
function customSort($a, $b) {
    if ($a['age'] == $b['age']) {
        return strcmp($a['name'], $b['name']);
    }
    return ($a['age'] < $b['age']) ? -1 : 1;
}

// Sort the multidimensional array based on both content and keys
uasort($multiArray, 'customSort');

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