Php-Arrays function-array_flip-exchange the key and value in the array. Array_flip () function exchanges keys and values in an array [function] This function returns an inverted array, that is, the value of the original array is changed to the key value of the new array, the key value of the original array is changed to the new array_flip () function to exchange the key and value in the 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]
$ 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
The http://www.bkjia.com/PHPjc/478206.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478206.htmlTechArticlearray_flip () function exchanges the keys and values in the array [function] This function returns an inverted array, that is, the value of the original array is changed to the key value of the new array, the key value of the original array is changed to new...