pTutorial

New way to learn PHP function

PHP array_flip() function

Syntax


array_flip ( $array )

Parameter Description
Array array to flip (Required)

Definition

It returns an array with the keys of $array as values, and the values of $array as the new keys.

Usage

array_flip function is used to exchange the key as value and value as a key.

Note: Keep in mind that array_flip() only flips the key/value mapping and does not reverse the positioning.

Example of array_flip function

<?php

$array = array
(
 "a" => "apple", 
 "b" => "banana", 
 "o"=>"orange"
 );

print_r( array_flip($array) ); 

?>

Array is an associative array variable that hold the three element. You can flip the key as a value and value as key using array_flip. You can see the after and before the array_flip function in above example.


More example of array_flip function

<?php

$name = array 
(
"php",
"java",
"html"
);

echo "before flip function used
"; print_r($name); echo "
after flip function used
"; print_r( array_flip($name)); ?>

QUOTES OF THE DAY

Saying is one thing, and doing is another.

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER