Swap all keys with their corresponding values in an array.
<?php $a1=array(“a”=>“red”,“b”=>“green”,“c”=>“blue”,“d”=>“yellow”); $result=array_flip($a1); print_r($result); ?> |
The array_flip() function swaps all keys with their corresponding values in an array.
array_flip(array) |
Parameter |
Description |
array |
Required. Specifies an array of key-value pairs to be swapped. |
Return Value: |
Returns the flipped array on success, or NULL on failure. |
PHP Version: |
4+ |