How to use array flip in PHP

In this article, I will explain how the array_flip() function can be used in PHP.
  • 2311

array_flip() function in PHP

  • array_flip() function returns an array with all the original keys as values and all original values as keys.

  • In array_flip() function, If a value has several occurrence, the latest key will be used as its values, and all others will be lost.

Syntax

array_flip(array)

Parameter

  • array start is the required parameter. the given array.

Example

The following example show to how the array_flip() function can be used in PHP.

<html>

<body>

<h3 style="color: darkmagenta;">array_flip() function example in PHP</h3>

    <?php

    $a=array(0=>"student",1=>"Advocate",2=>"Teacher");

    print_r(array_flip($a));

    ?>

</body>

</html>

 

Output

flip.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.