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;
}
Try this:
This can be done very simply, by using ucwords which accepts delimiter as param:
NOTE: Need php at least 5.4.32, 5.5.16
This function is similar to @Svens's function
But clearer, (i think :D) and with the optional parameter to capitalize the first letter or not.
Usage:
Here is a small helper function using a functional array_reduce approach. Requires at least PHP 7.0
I would probably use
preg_replace_callback()
, like this: