top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is array_flip function in PHP?

+1 vote
551 views
What is array_flip function in PHP?
posted Jun 10, 2014 by Amanpreet Kaur

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote

If you Google it you will find your answer in first Link.
Anyway this is the source

The array_flip() function flips/exchanges all keys with their associated values in an array.

Syntax: array_flip(array);

Example:

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$result=array_flip($a1);
print_r($result);
?>

Output

Array ( [red] => a [green] => b [blue] => c [yellow] => d )
answer Jun 11, 2014 by Divya Bharti
0 votes

array_flip exchange the keys with their associated values in array ie. Keys becomes values and values becomes keys.
<?php $arrayName = array("course1"=>"php","course2"=>"html"); $new_array = array_flip($arrayName); print_r($new_array); ?>
OUTPUT :
Array
(
[php] => course1
[html] => course2
)

answer Jun 12, 2014 by Mohit Sharma
...