PHP array_pad() function

PHP array_multisort() function
PHP array_pop() function

The function inserts a specified number of new elements with the specified value at the beginning of the end of the array.

You will understand the functioning after gaining through the syntax. However, a negative size parameter inserts new elements in the staring index of the array (before the original elements).

If the size parameter is less than the size of the array, no element will be discarded from the output.

What is the syntax of the array_oad function in PHP?

array_pad(array, size, value)
ParametersDetails
arraySpecify the array to pad – Required
sizeNumber of elements to return from the array – Required
valueSpecify the value to the newly inserted elements in the array – Required
array_pad function in PHP

Examples of array_pad function

<?php
$arr=array("pink","blue");
print_r(array_pad($arr,4,"green"));
?>

In the above example, we inserted an additional color to the array and return 4 elements of the array.

<?php
$arr=array("pink","blue");
print_r(array_pad($arr,-5,"green"));
?>

In the above example, we inserted an additional element at the beginning of the

array.

PHP array_multisort() function
PHP array_pop() function
en English
X
Scroll to Top