Example
Reverse the key names in the array and the corresponding associated key values:
"red","b"=>"green","c"=>"blue","d"=>"yellow"); $result=array_flip($a1); print_r($result); ?>
Definition and usage
array_flip() function is used to reverse/exchange arrays The key name in and the corresponding associated key value.
Syntax
array_flip(array);
Parameters | Description |
array | Required. Specifies the array whose key/value pairs need to be reversed. |
Technical details
Return value: | If the inversion is successful, the inversion is returned the array after. If the reversal fails, NULL is returned. |
PHP version: | 4+ |
integerorstring. A warning will be emitted if the value is of the wrong type, and the key/value pair in question will not be reversed.If the same value appears multiple times, the last key name will be used as its value, and all
otherswill be lost. array_flip() returns FALSE if it fails.
Example:
$hills=array("first"=>"data1″,"second"=>"data2″,"third"=>"data1″); $hills=array_flip($hills); //还原键名 $hills1=array_flip(array_flip($hills));//删除重复 display $hills1
data2 data1 two data.
The above is the detailed content of PHP function array_flip() used to reverse/exchange the key names in the array and the corresponding associated key values. For more information, please follow other related articles on the PHP Chinese website!