Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Fill an array with values

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 85
    Comment on it

    Hello friends,

    If you want to to fill a specific value as an array value then you can use a predefined PHP function "array_fill ( int $start_index , int $num , mixed $value )". This function returns an array filled by given values. In this $start_index is first index of the returned array, $num is the length of returned array and $value is value of returned array.

    Here is some example which will explain this function-

    <?php
    $a = array_fill(5, 6, 'New York');
    $b = array_fill(-2, 4, 'London');
    print_r($a);
    print_r($b);
    ?>
    

    Output:

    Array
    (
        [5]  => New York
        [6]  => New York
        [7]  => New York
        [8]  => New York
        [9]  => New York
        [10] => New York
    )
    Array
    (
        [-2] => London
        [0] => London
        [1] => London
        [2] => London
    )
    

 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: