PHP array_pad() Function
Definition
The array_pad() function inserts value to an array element.
A negative size means to insert before the array elements.
Syntax
PHP array_pad() Function has the following syntax.
array_pad(array,size,value)
Parameter
Parameter | Is Required | Description |
---|---|---|
array | Required. | Array to insert |
size | Required. | Number of elements to return |
value | Required. | Value to insert |
Example 1
Return 5 elements and insert a value of "blue" to the new elements in the array:
<?php
$a=array("A","B");
print_r(array_pad($a,5,"C"));
?>
The code above generates the following result.
Example 2
Using a negative size parameter:
<?php
$a=array("A","B");
print_r(array_pad($a,-5,"C"));
?>
The code above generates the following result.