Usage of array_flip function in php: [array_flip(array)]. The array_flip function is used to reverse all the key names and their associated key values in the array, and return the reversed array.
php array_flip function is used to reverse/exchange all key names and their associated key values in the array. Its syntax is array_flip(array), parameter array Required, specifies the array whose key/value pairs need to be reversed.
(Recommended tutorial: php video tutorial)
How to use the php array_flip function?
Function: Used to reverse/exchange all key names and their associated key values in the array.
Syntax:
array_flip(array);
Parameters:
array Required. Specifies the array whose key/value pairs need to be reversed.
Description:
Returns a reversed array. If the same value appears multiple times, the last key name will be its value, and all other keys will be used. Names will be lost. If the data type of the value in the original array is not string or integer, the function will report an error.
php array_flip() function usage example 1
<?php $a = array("class" => "php中文网","name" => "西门","job" => "讲师"); $result=array_flip($a); print_r($result); ?>
Output:
Array ( [php中文网] => class [西门] => name [讲师] => job )
php array_flip() function usage example 2
<?php $a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); $result=array_flip($a1); print_r($result); ?>
Output:
Array ( [red] => a [green] => b [blue] => c [yellow] => d )
The above is the detailed content of How to use array_flip function in php. For more information, please follow other related articles on the PHP Chinese website!