Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make every first character uppercase in array

Tags:

I'm trying to get all my first characters in a PHP array to be uppercase.

PHP code:

<?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/>"; } ?> 
like image 358
Victor Bjelkholm Avatar asked Jul 23 '10 04:07

Victor Bjelkholm


People also ask

How do you capitalize all first letters?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

How do you capitalize a string array?

To convert all array elements to uppercase:Use the map() method to iterate over the array. On each iteration, call the toUpperCase() method to convert the string to uppercase and return the result. The map method will return a new array with all strings converted to uppercase.

How do you replace the first character in a string with uppercase?

You can use str. title() to get a title cased version of the string. This converts the first character of each word in the string to uppercase and the remaining characters to lowercase.


1 Answers

$ord = array_map('ucfirst', $ord); 
like image 113
iroel Avatar answered Sep 23 '22 16:09

iroel