A::fill()
Fills an array up with additional elements to certain amount.
A::fill(array $array, int $limit, mixed $fill = 'placeholder'): array
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| $arrayrequired | array |
no default value | The source array |
| $limitrequired | int |
no default value | The number of elements the array should contain after filling it up. |
| $fill | mixed |
'placeholder'
|
The element, which should be used to fill the array. If it's a callable, it will be called with the current index |
Return type
array
The filled-up result array
Parent class
Examples
$array = [
'cat' => 'miao',
'dog' => 'wuff',
'bird' => 'tweet'
];
$result = A::fill($array, 5, 'elephant');
// result: [
// 'cat',
// 'dog',
// 'bird',
// 'elephant',
// 'elephant',
// ];