/**
* 引用递归数组首字母转小写(兼容此系统的代码命名规范)
*
* @param $array
* @return array
*/
protected function lowerArrayFirstWord(&$array)
{
if (!is_array($array)) {
return $array;
}
foreach ($array as $key => $value) {
$str = trim($key);
$first = $str[0]; //获取第一个字符
//只处理大写字母和数字
if (preg_match('/^[A-Z0-9]+$/', $first)) {
$array[lcfirst($key)] = $this->lowerArrayFirstWord($value);
//索引数组(下标为0)
if(!is_numeric($first)){
unset($array[$key]);
}
}
}
return $array;
}
$data = [
'Data' => '123',
'Body' => [
'Text' => '12334',
'Msg' => 'Databases',
'Add' => [
'a' => 1,
'B' => 2,
'3' => 3,
'C' =>['c1','c2']
],
],
];
$res = $this->lowerArrayFirstWord($data);
var_dump($res);exit;