Reverse the key names in the array and the corresponding associated key values:
<?php$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");$result=array_flip( $a1);print_r($result);?>The array_flip() function is used to reverse/exchange the key names in the array and the corresponding associated key values.
array_flip( array );
parameter | describe |
---|---|
array | Required. Specifies the array whose key/value pairs need to be reversed. |
Return value: | If the reversal is successful, the reversed array is returned. If the reversal fails, NULL is returned. |
---|---|
PHP version: | 4+ |