我有以下数组.
$state = array("gujarat","andhra_pradesh","madhya_pradesh","uttar_pradesh");
预期产出
$state = array("Gujarat","Andhra Pradesh","Madhya Pradesh","Uttar Pradesh");
我想使用UpperCase将单词的每个第一个字符转换为数组值,并将_替换为空格.所以我使用这个循环并按预期工作.
foreach($states as &$state) { $state = str_replace("_"," ",$state); $state = ucwords($state); }