PHP array_change_key_case() function
In this chapter you will learn:
- Description for PHP array_change_key_case() function
- Syntax for PHP array_change_key_case() function
- Parameter for PHP array_change_key_case() function
- Return value for PHP array_change_key_case() function
- Example for array_change_key_case() function
- 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
Parameter | Is Required | Description |
---|---|---|
array | Required. | Specifies the array to use |
case | Optional. | Case to use |
Possible values for case:
Value | Meaning |
---|---|
CASE_LOWER | Default value. Changes the keys to lowercase |
CASE_UPPER | Changes 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:
- Definition of PHP array_chunk() function
- Syntax for PHP array_chunk() function
- Parameter for PHP array_chunk() function
- Return from PHP array_chunk() function
- Example for PHP array_chunk() function
- Example - Split Associative arrays
Home » PHP Tutorial » PHP Array Functions