English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_flip() function usage and example

PHP Array Function Manual

The PHP array_flip() function returns the swapped keys and values in the array

Syntax

array array_flip(array $input);

Definition and usage

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.

Parameter

Serial numberParameters and descriptions
1

input

The array to be reversed

Return value

If it fails, it returns FALSE; otherwise, it reverses the array.

Online example

<?php
   $input = array("a"=>1, "b"=>2, "c"=>3, "d"=>4, "e"=>5;
   
   print_r(array_flip($input));
?>
Test and see ‹/›
Output result:
Array ( [1] => a [2] => b [3] => c [4] => d [5] => e )	

PHP Array Function Manual