💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
```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}) ```