Using array_map() to return a new array based on an existing array

Using array_map() to return a new array based on an existing array

Last updated:

Suppose you have an array of words and you want to create a new array which is the same as the original array but all its words are CAPITALIZED.

This is how you'd go about doing it.

$new_array = array_map(
   function($e){return strtoupper($e); },$original_array
   );

If the original array was ('foo','bar','baz'), the new array is now ('FOO','BAR','BAZ'). Simple.