The array_flip () function exchanges keys and values in an array.
[Function]
This function returns an array after inversion,
That is, the value of the original array is changed to the key value of the new array, and the key value of the original array is changed to the value of the new array.
If the array has the same value, only the last one with the same value will be reversed to the new array.
Scope of use]
Php4, php5.
[Use]
Array array_flip (array trans)
Trans/required/inverted Array
[Example]
[Php]
<? Php
$ Array1 = array ("blue" => 6, "red" => 2, "green" => 3, "purple" => 4 );
$ Array2 = array ("blue" => 6, "red" => 4, "green" => 6, "purple" => 4 );
$ Array3 = array ("blue" => 6, "red" => 4, "green" => 6, "purple" => '');
Print_r (array_flip ($ array1 ));
Print_r (array_flip ($ array2 ));
Print_r (array_flip ($ array3 ));
/*
Array
(
[6] => blue
[2] => red
[3] => green
[4] => purple
)
Array
(
[6] => green
[4] => purple
)
Array
(
[6] => green
[4] => red
[] => Purple
)
*/
Taken from zuodefeng's note