I l@ve RuBoard Previous Section Next Section

array_pad

array array_pad(array array, int pad_size, mixed pad_value) 

array

Array to pad

pad_size

Number of elements in resulting array

pad_value

Value to give to added elements

Pads an array with a specified number of elements with a given value.

Returns:

Original array, possibly padded to a greater number of elements; NULL on failure

Description:

This function pads the array passed in array with elements having the value given in pad_value until it contains the number of elements given by the absolute value of pad_size . If pad_size is positive, the new elements are added to the end of array . If pad_size is negative, the new elements are added to the beginning. If the absolute value of pad_size is equal to or less than the number of elements already in array , no elements are added.

Version:

PHP 4 since 4.0b4

Example:

Left-pad an array
$array = array(1, 2, 3, 4); 
$array = array_pad($array, -6, 'NEW'); 
print_r($array); 

Output: 
Array 
(
    [0] => NEW 
    [1] => NEW 
    [2] => 1 
    [3] => 2 
    [4] => 3 
    [5] => 4 
) 
    I l@ve RuBoard Previous Section Next Section