Pads an array with a value.
The array_pad() function extends an array to a size by adding the same value a number of times to either end of the array. The function returns a padded copy of the input array.
<?php
// 2, 3, 4, 5, 6, 7, 8
$array1 = range(2, 8);
// add some 9's to the end
$padded = array_pad($array1, sizeof($array1) + 4, 9);
// add some 1's to the beginning
$padded = array_pad($padded, -1 * (sizeof($padded) + 4), 1);
foreach ($padded as $element) {
print "$element ";
}
?>
1 1 1 1 2 3 4 5 6 7 8 9 9 9 9
The range() function is used to create an array. Then the array_pad() function is used to pad the array on both sides with 1's and 9's.