This function provides a very interesting use case for the PHP arrays. The developer may run into a situation where swapping of keys with values or vice versa is required. array_flip() function flips all the keys with their associated values.
What is the syntax of the array_flip() function in PHP?
array_flip(array)
Parameter | Details |
---|---|
array | The array of key/value pairs to flip its keys with their corresponding values |
Example of array_flip function
<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>