递归操作多维数组的键名
<?php
$database = [
'HosT' => 'localhost',
'poSt' => '3306',
'userName' => 'admin',
'paSsWord' => 'admin888',
'config' => [
'REDIS' => '127.0.0.1',
'POST' => 6379
]
];
function my_array_change_key_case(array $data , int $type = CASE_LOWER){
foreach($data as $key => $value) :
$action = $type ? 'strtoupper' : 'strtolower';
unset($data[$key]);
$data[$action($key)] = is_array($value) ? my_array_change_key_case($value) : $value;
endforeach;
return $data;
}
print_r(my_array_change_key_case($database));