array_pad
array_pad
Pad array to the specified length with a value
array **array_pad** array $array int $length mixed $value
returns a copy of the
padded to size specified by
with value
. If
is positive then the array is
padded on the right, if it's negative then on the left. If the
absolute value of is less than or
equal to the length of the then no
padding takes place.
array_pad``array``length``value``length``length``array
arrayInitial array of values to pad.
lengthNew size of the array.
value
Value to pad if is less than
.
array``length
Returns a copy of the padded to size specified
by with value
. If is
positive then the array is padded on the right, if it's negative then
on the left. If the absolute value of is less
than or equal to the length of the then no
padding takes place.
array``length``value``length``length``array
Voorbeeld: example
<?php
$input = array(12, 10, 9);
$result = array_pad($input, 5, 0);
// result is array(12, 10, 9, 0, 0)
echo join(', ', $result), PHP_EOL;
$result = array_pad($input, -7, -1);
// result is array(-1, -1, -1, -1, 12, 10, 9)
echo join(', ', $result), PHP_EOL;
$result = array_pad($input, 2, "noop");
// not padded
echo join(', ', $result), PHP_EOL;
?>
array_fill``range