Last active
April 7, 2021 15:26
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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