PHP array_flip() function

PHP array_filter() function
PHP array_intersect() function

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)
ParameterDetails
arrayThe array of key/value pairs to flip its keys with their corresponding values
array_flip function in PHP

Example of array_flip function

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

PHP array_filter() function
PHP array_intersect() function
en English
X
Scroll to Top