Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to interchange values and keys of an array in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 149
    Comment on it

    Hello Readers ,

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

    Say we have array array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow"); and we want to interchange key and values of an array .

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

    Output :

     Array ( [red] => a [green] => b [blue] => c [yellow] => d ) 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: