Given an array containing uppercase string elements and the task is to convert the array elements (uppercase) into lowercase. There are two ways to convert array values to lowercase in PHP.
- Using foreach loop
- Using array_map() function
Using foreach loop: In this approach, an iterator iterates through the value of an array individually and convert each array elements into lowercase and stores the converted values to the original array.
Program:
<?php // Declare an array $arr = array('GFG', 'GEEK', 'GEEKS', 'GEEKSFORGEEKS'); $j = 0; // Iterate loop to convert array // elements into lowercase and // overwriting the original array foreach( $arr as $element ) { $arr[$j] = strtolower($element); $j++; } // Dispaly the content of array foreach( $arr as $element ) echo $element . "\n"; ?> |
gfg geek geeks geeksforgeeks
Using array_map() function: In this approach, the array_map() function is used to accept two parameters callback and an array.
Syntax:
array array_map( callable callback, array array )
Here callback is a function to be called for operation on an array. This function can be an inbuilt function or an user-defined function whereas array is list of values on which operation to be performed.
Program 2:
<?php // Declare an array $arr = array('GFG', 'GEEK', 'GEEKS', 'GEEKSFORGEEKS'); $arr = array_map( 'strtolower', $arr ); // Display the content of array foreach( $arr as $element ) echo $element . "\n"; ?> |
gfg geek geeks geeksforgeeks
Recommended Posts:
- Uppercase Booleans vs. Lowercase in PHP
- AngularJS | angular.lowercase() Function
- AngularJS | lowercase Filter
- How to replace lowercase letters with an other character in JavaScript ?
- How to validate if input in input field has lowercase letters only using express-validator ?
- Lodash _.lowerCase() Method
- Mapping external values to dataframe values in Pandas
- How to Convert CSV to JSON file having Comma Separated values in Node.js ?
- How to print all the values of an array in PHP ?
- Convert an object to associative array in PHP
- How to convert array to SimpleXML in PHP
- How to convert an array into object using stdClass() in PHP?
- How to convert XML file into array in PHP?
- Convert multidimensional array to XML file in PHP
- How to convert PHP array to JavaScript or JSON ?
- How to convert an array to CSV file in PHP ?
- How to get multiple selected values of select box in php?
- PHP | Ds\Map values() Function
- How to return multiple values from function in PHP?
- How to convert Integer array to String array using JavaScript ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

