array_flip php array function to exachange the key and value

The “array_flip()” function exchanges all keys with their associated values within an array.

Syntax:

    array_flip(array)

In the above syntax “array” is the array for which the keys and values must be exchanged.

Example:

    <?php
    $a=array(0=>"Zero",1=>"One",2=>"Two");
    print_r(array_flip($a));
    ?>

Result:

     Array ( [Zero]=> 0 [One]=> 1 [Two]=> 2 )

In the above example array keys 0,1,2 of the array “$a” are exchanged with values Zero,One,Two to display the result.