使数组中的每个第一个字符首字母大写 [英] Make first every first character uppercase in array
本文介绍了使数组中的每个第一个字符首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正试图使我在PHP数组中的所有第一个字符都变为大写.
I'm trying to get all my first characters in a PHP array to be uppercase.
PHP代码:
<?php
$ordlista = file_get_contents('C:/wamp/www/bilder/filmlista.txt');
$ord = explode("\n", $ordlista);
sort($ord,SORT_STRING);
foreach ($ord as $key => $val) {
echo $val."<br/>";
}
?>
谢谢您的回答!
<?php
$ordlista = file_get_contents('C:/wamp/www/bilder/filmlista.txt');
$ord = explode("\n", $ordlista);
$ord=array_map(function($word) { return ucwords($word); }, $ord);
sort($ord,SORT_STRING);
foreach ($ord as $key => $val) {
echo $val."<br/>";
}
?>
推荐答案
$ord = array_map('ucfirst', $ord);
这篇关于使数组中的每个第一个字符首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文