How To

How to Use the Array_Change_Key_Case Function in PHP

Contributor
By eHow Contributing Writer
(1 Ratings)

The "array_change_key_case" function in PHP changes the indexes of the input array to all lowercase or uppercase if the indexes are strings. This function will not affect numeric indexes. The following steps will aid in your search for information about this function.

Difficulty: Moderately Challenging
Instructions
  1. Step 1

    Learn the syntax. The complete syntax is:

    array array_change_key_case (array $input [,int $case]).

    The brackets "[]" indicate an optional part. The optional case parameter can have two values, CASE_UPPER and CASE_LOWER, with CASE_LOWER being the default. Understand that if an array will have identical indexes after this function is run, the later index will override the previous index.

  2. Step 2

    Look at the following example for a simple case:

    $input_array = array("red" => 1, "BLUE" => 3, "Green" => 4);
    array_change_key_case($input_array,CASE_UPPER);
    ?>

    This example changes the index "red" to "RED," leaves the index "BLUE" unchanged since it was already upper case and changes the index "Green" to "GREEN." Note that the index is changed, not the value located at that index.

  3. Step 3

    Look at the following example without a case parameter:

    $input_array = array("RED" => 1, "BLUE" => 3);
    array_change_key_case($input_array);
    ?>

    This example changes the index "RED" to "red" and the index "BLUE" to "blue." Notice how the indexes were changed to lower case when the case parameter was not specified.

  4. Step 4

    Look at the following example to see what happens when this function would make two indexes identical:

    $input_array = array("RED" => 1, "BLUE" => 3, "red" => 5);
    array_change_key_case($input_array,CASE_UPPER);
    ?>

    This example gives us "RED" => 5 and "BLUE" => 3. Notice how "RED" => 1 was overridden by "RED" => 5.

Post a Comment

Post a Comment
  • Have you done this? Click here to let us know.
I Did This

Related Ads

Computers
Alexia Petrakos,

Meet Alexia Petrakos eHow's Computers Expert.

Get Free Computers Newsletters

Copyright © 1999-2009 eHow, Inc. Use of this web site constitutes acceptance of the eHow Terms of Use and Privacy Policy.   en-US

eHow Computers
eHow_eHow Technology and Electronics