Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Inserting array values at the beginning of an array in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 194
    Comment on it

    Hello Readers ,

    With the use of array_unshift() , it will insert new values at the beginning of an array.

    We can add one value, or as many as you like.

    Syntax:

    array_unshift(array,value1,value2,value3...) 
    

    Example:

    <?php
    $a=array("a"=>"red","b"=>"green");
    array_unshift($a,"blue");
    print_r($a);
    ?>
    

    Output:

     Array ( [0] => blue [a] => red [b] => green ) 
    

 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: