array_flip
Swap keys and values in arrays
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.
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
array_flip ( array ) ;
parameter | describe |
---|---|
array | Required. Specifies an array that needs to be reversed by key/value pairs. |