The array_flip() and array_change_key_case() functions in PHP are powerful tools for manipulating array keys. One swaps keys with values, while the other standardizes key casing.
array_flip(array)array_change_key_case(array, CASE_LOWER | CASE_UPPER)
// Flip keys and values of an associative array
<?php
$array = array("a" => "apple", "b" => "banana", "c" => "cherry");
$result = array_flip($array);
print_r($result);
?>
The values become keys and the keys become values. Useful for reverse lookups.
// Convert all array keys to lowercase
<?php
$array = array("a" => "apple", "B" => "banana", "C" => "cherry");
$result = array_change_key_case($array, CASE_LOWER);
print_r($result);
?>
// Convert all array keys to uppercase
<?php
$array = array("a" => "apple", "b" => "banana", "c" => "cherry");
$result = array_change_key_case($array, CASE_UPPER);
print_r($result);
?>
array_flip()