通知短信+运营短信,5秒速达,支持群发助手一键发送🚀高效触达和通知客户 广告
```php 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}) ```