How do I convert array values ​​to lowercase in PHP?

PHP

An array is given containing uppercase lowercase elements, and the task is to convert the array elements (uppercase) to lowercase. There are two ways to convert array values ​​to lowercase in PHP.
  • Using the foreach loop
  • Using the array_map()
Using the foreach loop :in this approach, the iterator iterates over the value of the array individually, converts each element of the array to lowercase, and stores the converted values ​​in the original array.Program:  
// Declare the array $arr = array ( 'GFG' , 'GEEK' , 'GEEKS' , ' GEEKSFORGEEKS' ); $j = 0;  
// Loop iterate to transform the array // lowercase elements and
// overwrite the original array foreach ( $arr as $element ) { $arr [ $j ] = strtolower ( $element ); $j ++; }  
// Display the contents of the array foreach ( $arr as $element ) echo $element . "" ;  
?>
Exit:
gfg geek engineer engineerforengineer
Using array_map():In this approach, array_map() is used to accept two callback and array parameters. 
Syntax:
array array_map (callable callback, array array)
Here's a callback - this is the function that is called to work with the array. This function can be a built-in or user-defined function, whereas the array - this is a list of values ​​to operate on.Program 2:  
// Declare the array $arr = array ( 'GFG' , ' GEEK' , 'GEEKS' , ' GEEKSFORGEEKS' ); $arr = array_map ( ' strtolower' , $arr );  
// Show array contents foreach ( $arr as $element ) echo $element . "" ;  
?>
Exit:
gfg geek engineer engineerforengineer