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)