我是PHP新手,我有一个数组,我想要回显,但要格式化,以便国家名称以正确的大小写形式书写,第一个字母大写。
例如:
cAnAdA回声为加拿大(Cap C)
SwitZerLand回声为瑞士(Cap S)
我知道strtoupper();全部大写,strtolower();全部小写,ucfirst();大写第一个字母,但我希望所有的大小写都转换为小写,然后第一个字母大写。
下面是我使用数组和foreach循环的代码。
<?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);
}提前谢谢你!!
发布于 2021-01-24 13:36:38
foreach($countries as $country){
echo ucwords(strtolower($country))
}https://stackoverflow.com/questions/65866126
复制相似问题