Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • array_fill_keys() in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 154
    Comment on it

    Hello Readers ,

    The array_fill_keys() function fills an array with values, specifying keys.

    For Example we have an array array("a","b","c","d"); and we want to put "blue" in all values of a key. See the below example.

    <!DOCTYPE html>
    <html>
    <body>
    
    <?php
    $keys=array("a","b","c","d");
    $a1=array_fill_keys($keys,"blue");
    print_r($a1);
    ?>
    
    </body>
    </html>
    

    Output:

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

 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: