Can someone help me complete this PHP function? I want to take a string like this: 'this-is-a-string' and convert it to this: 'thisIsAString':
function dashesToCamelCase($string, $capitalizeFirstCharacter = false) {
// Do stuff
return $string;
}
Another simple approach:
If you use Laravel framework, you can use just camel_case() method.
Untested code. Check the PHP docs for the functions im-/explode and ucfirst.
Alternatively, if you prefer not to deal with regex, and want to avoid explicit loops:
In Laravel use
Str::camel()
One liner, PHP >= 5.3: