From a1a9f22b59d1ac05bc3eecd8933ade8a47ef63fa Mon Sep 17 00:00:00 2001 From: abuyoyo Date: Wed, 5 Aug 2020 20:51:15 +0300 Subject: [PATCH] camelCaseKeys() polyfill --- notice-manager.php | 1 + src/utilities.php | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/utilities.php diff --git a/notice-manager.php b/notice-manager.php index 0eabafd..a221f88 100644 --- a/notice-manager.php +++ b/notice-manager.php @@ -53,6 +53,7 @@ new PluginCore( ] ); +require_once 'src/utilities.php'; require_once 'src/NoticeManager.php'; diff --git a/src/utilities.php b/src/utilities.php new file mode 100644 index 0000000..1e6c953 --- /dev/null +++ b/src/utilities.php @@ -0,0 +1,49 @@ + $val) { + $newKey = @explode('_', $key); + //array_walk($newKey, create_function('&$v', '$v = ucwords($v);')); //If you are using PHP 5.3.0 or newer a native anonymous function should be used instead. + array_walk($newKey, function(&$v){$v = ucwords($v);}); + $newKey = @implode('', $newKey); + $newKey = @lcfirst($newKey); //$newKey{0} = strtolower($newKey{0}); + + /* if (! $newKey = @ucwords($key, '_') ) + $newKey = $key; + $newKey = @str_replace('_', '', $newKey); + $newKey = @lcfirst($newKey); */ + + if (!is_array($val)) { + $camelCaseArray[$newKey] = $val; + } else { + //this line throws an 'index undefined' notice + //$camelCaseArray[$newKey] = camelCaseKeys($val, $camelCaseArray[$newKey]); + + //$camelCaseArray[$newKey] = camelCaseKeys($val, $array[$key]); //? this works? why? + //$camelCaseArray[$newKey] = camelCaseKeys($val, $val); //? this works? why? + $camelCaseArray[$newKey] = camelCaseKeys($val); //? this works? why? + } + } + return $camelCaseArray; +} +endif; \ No newline at end of file