array_pad() function expands an array to a precise size, padding it with a default value.
//Its syntax is: array array_pad(array array, int pad_size, mixed pad_value);
pad_size specifies the new length of the array.
pad_value parameter specifies the default value.
If pad_size is positive, then the array will be padded to the right;
If pad_size is negative, the array will be padded to the left.
If the absolute value of pad_size is less than or equal to the length of the array, then no action will be taken.
<?
$weights = array (1, 3, 5, 10, 15);
$weights = array_pad($weights, 10, 100);
print_r($weights);
?>
Related examples in the same category