Skip to content

Instantly share code, notes, and snippets.

@NBoulfroy
Last active April 7, 2021 15:26
Show Gist options
  • Save NBoulfroy/0e545c4c2cc7d3a63fdc63ed37fc53c2 to your computer and use it in GitHub Desktop.
Save NBoulfroy/0e545c4c2cc7d3a63fdc63ed37fc53c2 to your computer and use it in GitHub Desktop.
[Camel case formatter] Function to format a snake case string to camal case string #PHP
<?php
/**
* @param string $string
*
* @return string
*/
function camelCaseFormatter($string) {
$format = null;
$stringExplode = explode('_', $string);
for ($i = 0; $i < count($stringExplode); ++$i) {
if ($i !== 0) {
$format .= ucwords($stringExplode[$i]);
} else {
$format .= lcfirst($stringExplode[$i]);
}
}
return $format;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment