Current Location: Home> Function Categories> array_flip

array_flip

Swap keys and values ​​in arrays
Name:array_flip
Category:Array
Programming Language:php
One-line Description:Swap keys and values ​​in an array.

Definition and usage

array_flip() function is used to invert/exchange all key names in an array and their associated key values.

array_flip() function returns an inverted array. If the same value appears multiple times, the last key name will be its value and all other key names will be lost.

If the data type of the value in the original array is not a string or an integer, the function will report an error.

Example

Invert all keys in the array and their associated values:

 <?php
$a1 = array ( "a" => "red" , "b" => "green" , "c" => "blue" , ​​"d" => "yellow" ) ;
$result = array_flip ( $a1 ) ;
print_r ( $result ) ;
?>

Try it yourself

grammar

 array_flip ( array ) ;
parameter describe
array Required. Specifies an array that needs to be reversed by key/value pairs.
Similar Functions
Popular Articles