I am new to PHP and I have an array and I would like to echo, but formatted so that the country names are written in the proper cases with the first letter capitalized.
For example:
cAnAdA echos as Canada (Cap C)
SwitZerLand echos as Switzerland (Cap S)
I know strtoupper(); all uppercase, strtolower(); all lowercase and ucfirst(); capitalize the first letter, but I want all the cases converted to lowercase and then the first letter capitalized.
Below is my code with the array and foreach loop.
<?php
$countries = [
'cAnAdA',
'SwitZerLand',
'GrEEce',
'HUnGary',
'CroATia',
'IndOneSia',
'IrElAnd',
'InDia',
'MonGoLia',
'UNitED StaTes of AmeriCA',
'ChiNa',
'romaNia',
'Poland',
'SieRRA LeoNe',
'fraNcE',
'JaPAn',
'Belgium',
'TuRkEy',
'Aland islANds',
'YeMen',
'Egypt',
];
foreach($countries as $country){
echo strtoupper($country);
}
Thank you in advance!!
question from:
https://stackoverflow.com/questions/65866126/is-there-a-way-to-reformat-an-array-when-echoing-the-foreach-loop 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…