PHP array_change_key_case() function

In this chapter you will learn:

  1. Description for PHP array_change_key_case() function
  2. Syntax for PHP array_change_key_case() function
  3. Parameter for PHP array_change_key_case() function
  4. Return value for PHP array_change_key_case() function
  5. Example for array_change_key_case() function
  6. Example - If two or more keys will be equal after running array_change_key_case()

Description

The array_change_key_case() function changes all keys in an array to lowercase or uppercase.

Syntax

PHP array_change_key_case() function has the following syntax.

array_change_key_case(array,case);

Parameter

ParameterIs RequiredDescription
arrayRequired.Specifies the array to use
caseOptional.Case to use

Possible values for case:

ValueMeaning
CASE_LOWERDefault value. Changes the keys to lowercase
CASE_UPPERChanges the keys to uppercase

Return

array_change_key_case() function returns an array with its keys in lowercase or uppercase, or FALSE if array is not an array.

Example

Change the lowercase key to uppercase.


<?php
    $age=array("a"=>"a","b"=>"b","c"=>"c");
    print_r(array_change_key_case($age,CASE_UPPER));
?>

The code above generates the following result.

Example 2

If two or more keys will be equal after running array_change_key_case() (e.g. "b" and "B"), the latest array will override the other.


<?php
    $pets=array("a"=>"a","b"=>"b","B"=>"B","A"=>"A");
    print_r(array_change_key_case($pets,CASE_UPPER));
?>

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. Definition of PHP array_chunk() function
  2. Syntax for PHP array_chunk() function
  3. Parameter for PHP array_chunk() function
  4. Return from PHP array_chunk() function
  5. Example for PHP array_chunk() function
  6. Example - Split Associative arrays
Home » PHP Tutorial » PHP Array Functions
PHP array() function
PHP array_change_key_case() function
PHP array_chunk() function
PHP array_combine() function
PHP array_count_values() function
PHP array_diff() function
PHP array_diff_assoc() Function
PHP array_diff_key() function
PHP array_diff_uassoc() function
PHP array_diff_ukey() function
PHP array_fill() function
PHP array_fill_keys() function
PHP array_filter() function
PHP array_flip() function
PHP array_intersect() Function
PHP array_intersect_assoc() Function
PHP array_intersect_key() function
PHP array_intersect_uassoc() Function
PHP array_intersect_ukey() Function
PHP array_key_exists() Function
PHP array_keys() function
PHP array_map() Function
PHP array_merge() function
PHP array_merge_recursive() Function
PHP array_multisort() Function
PHP array_pad() Function
PHP array_pop() function
PHP array_product() Function
PHP array_push() function
PHP array_rand() function
PHP array_reduce() Function
PHP array_replace() Function
PHP array_replace_recursive() Function
PHP array_reverse() Function
PHP array_search() Function
PHP array_shift() Function
PHP array_slice() Function
PHP array_splice() Function
PHP array_sum() Function
PHP array_udiff() Function
PHP array_udiff_assoc() Function
PHP array_udiff_uassoc() Function
PHP array_uintersect() Function
PHP array_uintersect_assoc() Function
PHP array_uintersect_uassoc() Function
PHP array_unique() Function
PHP array_unshift() Function
PHP array_values() Function
PHP array_walk() Function
PHP array_walk_recursive() Function
PHP arsort() Function
PHP asort() Function
PHP compact() Function
PHP count() Function
PHP current() Function
PHP each() Function
PHP end() Function
PHP explode() Function
PHP extract() Function
PHP implode() Function
PHP in_array() Function
PHP key() Function
PHP krsort() Function
PHP ksort() Function
PHP list() Function
PHP natcasesort() Function
PHP natsort() Function
PHP next() Function
PHP pos() Function
PHP prev() Function
PHP range() Function
PHP reset() Function
PHP rsort() Function
PHP shuffle() Function
PHP sizeof() Function
PHP sort() Function
PHP uasort() Function
PHP uksort() Function
PHP usort() Function