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