search for in the  
<Arraysarray_chunk>
Last updated: Thu, 19 May 2005

array_change_key_case

(PHP 4 >= 4.2.0, PHP 5)

array_change_key_case -- Returns an array with all string keys lowercased or uppercased

Description

array array_change_key_case ( array input [, int case] )

array_change_key_case() changes the keys in the input array to be all lowercase or uppercase. The change depends on the last optional case parameter. You can pass two constants there, CASE_UPPER and CASE_LOWER. The default is CASE_LOWER. The function will leave number indices as is.

Example 1. array_change_key_case() example

<?php
$input_array
= array("FirSt" => 1, "SecOnd" => 4);
print_r(array_change_key_case($input_array, CASE_UPPER));
?>

The above example will output:

Array
(
    [FIRST] => 1
    [SECOND] => 4
)

If an array has indices that will be the same once run through this function (e.g. "keY" and "kEY"), the value that is later in the array will override other indices.



User Contributed Notes
array_change_key_case
benles at bldigital dot com
05-Mar-2005 07:20
In case you want to find the original case of a key:

$arr = Array( "a"=>1, "B"=>2);

function array_get_key_case($arr, $k)
{
   $s = strtolower($k);
   foreach (array_keys($arr) as $key) if (strtolower($key) == $s) return $key;
  return $k;
}

// Should print aBC
echo array_get_key_case($arr, "A");
echo array_get_key_case($arr, "B");
echo array_get_key_case($arr, "C");
aidan at php dot net
01-Jun-2004 10:06
This functionality is now implemented in the PEAR package PHP_Compat.

More information about using this function without upgrading your version of PHP can be found on the below link:

http://pear.php.net/package/PHP_Compat
euphoria{AT}netdoor.org
17-Nov-2002 11:31
Just a note, this function kills any name-clashes!  Say you had:
$array = array('key1' => 'abc', 'key2' => 'def', 'KEY1' => 'ghi');
$array = array_change_key_case($array);

then you would end up with:
Array
(
   [key1] => ghi
   [key2] => def
)

(Change .org to .com to e-mail me)
Armond

<Arraysarray_chunk>
 Last updated: Thu, 19 May 2005
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: The Server Pages
Last updated: Thu May 19 17:35:34 2005 CDT