pad()
The pad() method pad array to the specified length with a value
<?php use kim\present\utils\arrays\ArrayUtils;
$arrayUtils = ArrayUtils::from(range(1,5));
//Fill with 0 to have 10 elements
$arrayUtils->pad(10, 0);
// expected output: [1, 2, 3, 4, 5, 0, 0, 0, 0, 0]
//Fill with 0 to have 10 elements, append to front of array
$arrayUtils->pad(-10, 0);
// expected output: [0, 0, 0, 0, 0, 1, 2, 3, 4, 5]Syntax
$arrayUtils->pad(int $size, mixed $value) : ArrayUtils;Parameter
$sizeNew size of the array.
$valueValue to pad if
arrayis less thansize.
Return value
A padded array.
Prefixing
$arrayUtils->padAs(int $size, mixed $value) : array;ArrayUtils::padFrom(iterable $from, int $size, mixed $value) : ArrayUtils;ArrayUtils::padFromAs(iterable $from, int $size, mixed $value) : array;References
Last updated