Comment on page
pad()
The pad() method pad array to the specified length with a value
Example.php
<?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]
$arrayUtils->pad(int $size, mixed $value) : ArrayUtils;
$size
- New size of the array.
$value
- Value to pad if
array
is less thansize
.
- A padded array.
$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;
Last modified 3yr ago