English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_pad() function fills a value into an array with a specified length
array_pad ( $array, $pad_size, $pad_value );
array_pad() returns a copy of array and fills it with value pad_size specified length. If pad_size If positive, it fills to the right of the array, if negative, it starts filling from the left. If pad_size The absolute value is less than or equal to the length of the array then there is no filling. It is possible to fill up to 1048576 units.
Serial Number | Parameters and Description |
---|---|
1 | array(Required) It specifies an array. |
2 | pad_size(Required) It specifies the number of elements in the array returned by the function. |
3 | pad_value(Required) It specifies the value of the new elements in the array returned by the function. |
It returns a copy of an array whose size is specified by pad_size and the value pad_value.
array_pad() Example
<?php $input1 = array("a"=>"Cavalo","b"=>"Gato","c"=>"Cão"); print_r(array_pad($input1,7, ''COW'')) ?>Teste veja‹/›
Output Result:
Array ( [a] => Cavalo [b] => Gato [c] => Cão [0] => COW [1]] => COW [2]] => COW [3]] => COW )