Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • array_pad function php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    Welcome to FindNerd. Today we are going to discuss the function array_pad which is used to build another array by specifing the size of the array and value to be added. You can take an example for the same. Please have a look.

    <?php
    $base_arr = array('name'=>'Mohan','age'=>23);
    $output_arr = array_pad($base_arr,4,'paid');
    ?>
    result: array('name'=>'Mohan','age'=>23,[0]=>'paid',[1]=>'paid')
    

    In above example we created array with two new values paid. it can add 1048576 elements in one attempt. You can add the elements in both directoins right and left. Please have a look.

     <?php
    $base_arr = array('Mohan',23);
    $output_arr = array_pad($base_arr,-4,'paid');
    ?>
    result: array([-2]=>'paid',[-1]=>'paid',[0]=>'Mohan',[1]=>23)
    

 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: