Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Exchanges all keys with their associated values in an array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 84
    Comment on it

    Hello friends,

    This time I am here to explain a very common issue in php which if is someone want to exchange the array keys with values, for this you can use a predefined php array function "array_flip ( array $array )". array_flip ( $array ) used for exchange the values with keys of the array.

    Here is some example-

    <?php
    $input = array("oranges", "apples", "pears");
    $flipped = array_flip($input);
    
    print_r($flipped);
    ?>
    

    Output:

    Array
    (
        [oranges] => 0
        [apples] => 1
        [pears] => 2
    )
    

 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: