多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ function to_slash($array) { // 先转成json字符串,进行正则替换,再转换为数组 $tmp = json_encode($array); $tmp = strtolower(preg_replace('/((?<=[a-z])(?=[A-Z]))/', '_', $tmp)); $tmp = json_decode($tmp, true); return $tmp; } 原理: // 驼峰转下划线 // 先添加分隔符,再转成小写 // userId => user_id $str = preg_replace('/((?<=[a-z])(?=[A-Z]))/','_',$str); $str = strtolower($str); // 下划线转驼峰 // 同样先添加分隔符,再转成大写 // user_id => userId $array = explode('_',$str); array_walk($array,create_function('&$v','$v=ucwords($v);')); $str = implode('',$array); // 首字母转小写 $str{0} = strtolower($str{0}) ~~~