Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. <?php
  2. function array_key_camelize($array)
  3. {
  4. $result = [];
  5. foreach ($array as $key => $value) {
  6. $result[camelize($key)] = is_array($value) ? array_key_camelize($value) : $value;
  7. }
  8. return $result;
  9. }
  10.  
  11. function camelize($str)
  12. {
  13. return preg_replace_callback('/[_-]([^-_])/',
  14. function ($m) { return strtoupper($m[1]); },
  15. $str);
  16. }
  17.  
  18. $array = [
  19. 'this_is_snake_case' => 'this_is_snake_case',
  20. 'this-is-kebab-case' => 'this-is-kebab-case',
  21. 'nest' => [
  22. 'this_is_snake_case' => 'this_is_snake_case',
  23. 'this-is-kebab-case' => 'this-is-kebab-case',
  24. ]
  25. ];
  26.  
  27. var_dump($array);
  28. var_dump(array_key_camelize($array));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement