What is the best way to replace field names in multidimensional arrays in PHP?

When working with multidimensional arrays in PHP, you may need to replace specific field names with new names. One way to achieve this is by iterating through the array and using the array_keys() and array_combine() functions to replace the field names.

// Sample multidimensional array
$array = [
    ['id' => 1, 'name' => 'John'],
    ['id' => 2, 'name' => 'Jane']
];

// Define the mapping of old field names to new field names
$mapping = ['id' => 'user_id', 'name' => 'full_name'];

// Iterate through the array and replace field names
foreach ($array as &$item) {
    $item = array_combine(array_map(function($key) use ($mapping) {
        return $mapping[$key];
    }, array_keys($item)), $item);
}

// Output the modified array
print_r($array);