PHP array_flip: Swap Array Keys & Values
The array_flip function is used to swap the keys and values in an array. Here is how to use it:
$array = array("a" => "apple", "b" => "banana", "c" => "cherry");
$flippedArray = array_flip($array);
print_r($flippedArray);
The output result is:
Array
(
[apple] => a
[banana] => b
[cherry] => c
)
Caution: If the values in the original array are not unique, they may be overwritten when using the array_flip function.