News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

How to Use the Array_Change_Key_Case Function in PHP

Started by ganeshbala, Aug 20, 2008, 03:26 PM

Previous topic - Next topic

ganeshbala

Array_Change_Key_Case Function in PHP

The complete syntax is:

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

For example


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.


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.


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.


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.