The array_flip Function
The array_flip
function exchanges
all keys with their associated values in an array.
Syntax
array_flip(array $array): array
Example
Let's exchange the keys and values of the array:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5];
var_dump(array_flip($arr));
?>
Code execution result:
[1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd', 5 => 'e']
See Also
-
the
array_reverse
function,
which reverses an array