Tag Archives: array uppercase

Convert all string values of an array to upper/lower case without using loop

Today I have got a mail about how to convert all the string values of an array to upper/lower case without having to use a loop. 
Here is a solution:

  1. Put the array into a string by implode().
  2. Then convert this string into upper/lowercase by: strtoupper() or strtolower() function.
  3. Now convert the string into array by explode().
<?php
$inputArray = array('First', 'Second', 'Third', 'Fourth');

$inputString = implode(',', $inputArray);

//$outputString = strtolower($inputString);
$outputString = strtoupper($inputString);

$outputArray = explode(',', $outputString);

echo '<pre>'; print_r($outputArray); echo '</pre>';
?>

Output:

Array
(
	[0] => FIRST
	[1] => SECOND
	[2] => THIRD
	[3] => FOURTH
)
Advertisements