English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_flip() function returns the swapped keys and values in the array
array array_flip(array $input);
array_flip() returns an array that has been reversed, for example, the key names in the array become the values, and the values in the array become the key names.
Note that the values in the array must be able to act as valid key names (for example, they need to be integer or string). If the type is incorrect, a warning will be issued, and the problematic key/value pair will not appear in the result.
If the same value appears multiple times, the last key name will be used as its value, and other keys will be discarded.
Serial number | Parameters and descriptions |
---|---|
1 | input The array to be reversed |
If it fails, it returns FALSE; otherwise, it reverses the array.
<?php $input = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5; print_r(array_flip($input)); ?>Test and see ‹/›
Array ( [1] => a [2] => b [3] => c [4] => d [5] => e )