php递归调用使数组键名大写变成下划线加小写
// 递归调用使数组键名大写变成下划线加小写结合ccFormat函数
if (!function_exists('arrBigToSmall')) {
function arrBigToSmall($arr) {
// static $tree = array();
$tree = array();
foreach ($arr as $key => $value) {
$minKey = ccFormat($key);
if (is_array($value)) {
$tree[$minKey] = arrBigToSmall($value);
} else {
$tree[$minKey] = $value;
}
}
return $tree;
}
}
// php把大写命名转换成下划线分割命名
if (!function_exists('ccFormat')) {
function ccFormat($name) {
$name = lcfirst($name);
$temp_array = array();
for ($i = 0; $i < strlen($name); $i++) {
$ascii_code = ord($name[$i]);
if ($ascii_code >= 65 && $ascii_code <= 90) {
if ($i == 0) {
$temp_array[] = chr($ascii_code + 32);
} else {
$temp_array[] = '_' . chr($ascii_code + 32);
}
} else {
$temp_array[] = $name[$i];
}
}
return implode('', $temp_array);
}
}