PHP array_pad() Function
In this chapter you will learn:
- Definition for PHP array_pad() Function
- Syntax for PHP array_pad() Function
- Parameter for PHP array_pad() Function
- Example - Return 5 elements and insert a value of "blue" to the new elements in the array
- Example - Using a negative size parameter
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.
Next chapter...
What you will learn in the next chapter:
- Syntax for PHP array_pop() function
- Definition for PHP array_pop() function
- Parameter for PHP array_pop() function
- Note for PHP array_pop() function
- Example - Popup value from an Array
- Example - Popup element from associate array
Home » PHP Tutorial » PHP Array Functions