Special Offer - Get $90 Discount and Host Your Dream Web Site @ Dreamhost for 1 Year Click Here. Promo Code SLJ345
Back To Top
WordPress Web Application Development
Develop Powerfull Web Applications Using Cutting Edge WordPress Development Techniques

Converting Array Values To Uppercase Using PHP Array Functions

on 2011/08/21 11:50 PM stored in: Uncategorized and tagged:

Converting Array Values To Uppercase

In this post i am going to explain how to convert all the values of a php array into uppercase. This is important if your arrays are used in a case sensitive matching or validation. This can be achieved using 2 methods as shown below.

Method 1 – Looping through the array and converting to uppercase

In this method we have to loop through the array and convert each array value to uppercase. Then we need to add the converted value to a new array.

$sample_array = array("mark","steve","adam");
$converted_array = array();

foreach($sample_array as $key=>$value){
       $uppercase_value = strtoupper($value);
       array_push($uppercase_value,$converted_array);
}

Method 2 – Using php array_map function

Using this method we can convert array values using a single line of code. This function can be used to apply single function on every array element without looping through the array manually. This method is recommended for converting array values.

$sample_array = array("mark","steve","adam");

$converted_array = array_map("strtoupper", $sample_array);

3 Responses to “Converting Array Values To Uppercase Using PHP Array Functions”

  1. inteligentne Says:

    Very nice post. I just stumbled upon your weblog and wanted to say that I have truly enjoyed browsing your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

  2. Says:

    I love reading these articles beacsue they’re short but informative.

Leave a Reply

Follow Us On Facebook