|
|
@@ -94,4 +94,36 @@ class arrayUtil
|
|
|
{
|
|
|
return array_unique(array_filter(array_column($arr, $col)));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 描述:驼峰/下划线 互转
|
|
|
+ * 参数:{
|
|
|
+ * "params": "待转换数组",
|
|
|
+ * "type": "默认 0: 驼峰-》下划线;1:下划线-》驼峰"
|
|
|
+ * }
|
|
|
+ */
|
|
|
+ public static function humpUnderlineConversion($params, $type = 0) {
|
|
|
+ $newArr = [];
|
|
|
+ if (!is_array($params) || empty($params)) return $newArr;
|
|
|
+ foreach ($params as $key => $val){
|
|
|
+ if ($type == 1) {
|
|
|
+ $newkey = preg_replace_callback('/([-_]+([a-z]{1}))/i', function ($matches) {
|
|
|
+ return strtoupper($matches[2]);
|
|
|
+ }, $key);
|
|
|
+ } else {
|
|
|
+ $newkey = $key;
|
|
|
+ if (!strstr($key, '_')) {
|
|
|
+ $key = str_replace("_", "", $key);
|
|
|
+ $key = preg_replace_callback('/([A-Z]{1})/', function ($matches) {
|
|
|
+ return '_' . strtolower($matches[0]);
|
|
|
+ }, $key);
|
|
|
+ $newkey = ltrim($key, "_");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $newArr[$newkey] = is_array($val) ? self::humpUnderlineConversion($val, $type) : $val;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $newArr;
|
|
|
+ }
|
|
|
}
|