PHP array_pad() Function
Complete PHP Array Reference Manual
Example
Return 5 elements and insert the value "blue" into the new elements of the array:
Run Example »
Definition and Usage
The array_pad() function inserts a specified number of elements with a specified value into an array.
**Tip:** If you set the size parameter to a negative number, the function inserts new elements before the original array (see the example below).
**Note:** If the size parameter is smaller than the length of the original array, the function will not delete any elements.
Syntax
array_pad(
array,size,value
)
| Parameters | Description |
|---|---|
| array | Required. Specifies the array. |
| size | Required. Specifies the number of elements in the array returned by the function. |
| value | Required. Specifies the value of the new elements in the array returned by the function. |
Technical Details
| Return Value: | Returns an array with the new elements. |
|---|---|
| PHP Version: | 4+ |
More examples
Example 1
Using a negative size parameter:
Run Example »
Complete PHP Array Reference Manual