You are given an array of strings. You have to change all of the strings present in the given array to uppercase no matter in which case they are currently. Print the resultant array.
Input : arr = ("geeks", "For", "GEEks") Output : Array (=>GEEKS =>FOR =>GEEKS) Input : arr = ("geeks") Output : Array (=>GEEKS)
To solve this problem one of the basic approach is to iterate over all string of input array and then change them to uppercase on by one and print them. Iterating over array makes a quite use of for loop in program which can be avoided by using some smart methods like array_change_key_case() and array_flip(). What we have to do is just flip the array keys to value and vice-versa after that change the case of new keys of array which actually changes the case of original strings value and then again flip the key and values by array_flip().
Below is the step by step process:
- use array_flip() function swap keys with the values present in the array.
That is, the keys will now become values and their respective values will be their new keys.
- use array_change_key_case() function to change case of current keys(original values).
- use array_flip() function again to flip key and values of array to obtain
original array where strings value are in upper case.
Below is the implementation of above approach in PHP:
Array before string conversion: Array (  => Practice  => ON  => GeeKs  => is best ) Array after string conversion: Array (  => PRACTICE  => ON  => GEEKS  => IS BEST )
- Uppercase Booleans vs. Lowercase in PHP
- AngularJs | uppercase Filter
- AngularJS | angular.uppercase() Function
- How to trim all strings in an array in PHP ?
- PHP | Sort array of strings in natural and standard orders
- CSS | will-change property
- How to change the thickness of hr tag using CSS ?
- How to change the height of br tag?
- How to change the style of alert box using CSS ?
- How to change color of PNG image using CSS?
- AngularJS | ng-change Directive
- How to change favicon dynamically?
- How to change the element id using jQuery ?
- How to detect the change in DIV's dimension ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.