Reputation: 58662
I work with Apple Product Name a lot
"iphone"
"ipad"
"imac"
What would be the quickest way to make the second character uppercase?
"iPhone"
"iPad"
"iMac"
// $name = iphone
if ($name[0] == 'i') {
strtoupper($name[1]);
dd($name); //iphone
}
Upvotes: 2
Views: 1327
Reputation: 1082
Perfect answer
$word ='iphone';
$result = str_replace(substr($word,1,1),ucfirst(substr($word,1,1)),$word);
echo $result;
Upvotes: 2
Reputation: 2823
You have to replace the value in original variable:
$name[1] = strtoupper($name[1]);
Upvotes: 9