Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function array_key_camelize($array)
- {
- $result = [];
- foreach ($array as $key => $value) {
- $result[camelize($key)] = is_array($value) ? array_key_camelize($value) : $value;
- }
- return $result;
- }
- function camelize($str)
- {
- return preg_replace_callback('/[_-]([^-_])/',
- function ($m) { return strtoupper($m[1]); },
- $str);
- }
- $array = [
- 'this_is_snake_case' => 'this_is_snake_case',
- 'this-is-kebab-case' => 'this-is-kebab-case',
- 'nest' => [
- 'this_is_snake_case' => 'this_is_snake_case',
- 'this-is-kebab-case' => 'this-is-kebab-case',
- ]
- ];
- var_dump($array);
- var_dump(array_key_camelize($array));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement