array_flip in php example

The array_flip() changes key to value and value to key of the given array.

Syntax:

array_flip($array);

 Program: array_flip.php

<?php
$arr_original=array(1=>sunday,2=>monday,3=>tuesday,4=>wednesday,5=>thursday,6=>friday,7=>saturday);
echo "Original array is \t\t\n";
print_r($arr_original);
$arr_flipped=array_flip($arr_original);     
//arr_original array’s key changed to values and values changed to keys.
echo "Flipped array is \t\t\n";
print_r($arr_flipped);
?>

 

Output:

array_flip output

 

 

 

Thanks for reading this post…………….!!!

Leave a Reply