Change all keys in an array to uppercase and overwrite other entries in PHP

Description

The following code shows how to change all keys in an array to uppercase and overwrite other entries.

Example


/*from  ww  w.ja v a 2s  .co  m*/
//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"=>"Apple","B"=>"Dog","c"=>"Cat","b"=>"Bird");
    print_r(array_change_key_case($pets,CASE_UPPER));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone