array_pad() function expands an array to a precise size, padding it with a default value. : array_pad « Data Structure « PHP






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

1.Add new values to the beginning of the array by using a negative value for $size:
2.An array that is padded from the front
3.Setting an Array's Size: array array_pad(array $input, int $size, mixed $value)
4.Using array_pad() with associative arrays
5.array_pad 1
6.array_pad 2
7.array_pad 3
8.Pad array to the specified length with a value