Array_pad () fills an array with a value to the specified length [function] This function returns a copy of the specified array and fills it with the specified value to the specified length. If the specified length is positive, the array is filled to the right. if the length is negative, the array is filled from the left. If the length is specified, the limit is... SyntaxHighlighter. all ();
Array_pad () fills the array with a value to the specified length
[Function]
This function returns a copy of the specified array and fills it with the specified value to the specified length.
If the specified length is positive, the array is filled to the right. if the length is negative, the array is filled from the left.
If the absolute value of the specified length is smaller than or equal to the length of the original array, nothing is filled.
It is possible that up to 1048576 array elements can be filled at a time.
Scope of use]
Php4, php5.
[Use]
Array array_pad (array input, int pad_size, mixed pad_value)
Input/required/original array
Pad_size/required/the specified length to be filled
Pad_value/required/specified value
[Example]
[Php]
$ Input = array (12, 10, 9 );
Var_dump (array_pad ($ input, 5, 0 ));
Var_dump (array_pad ($ input,-7,-1 ));
Var_dump (array_pad ($ input, 2, "noop "));
/*
Array (5 ){
[0] =>
Int (12)
[1] =>
Int (10)
[2] =>
Int (9)
[3] =>
Int (0)
[4] =>
Int (0)
}
Array (7 ){
[0] =>
Int (-1)
[1] =>
Int (-1)
[2] =>
Int (-1)
[3] =>
Int (-1)
[4] =>
Int (12)
[5] =>
Int (10)
[6] =>
Int (9)
}
Array (3 ){
[0] =>
Int (12)
[1] =>
Int (10)
[2] =>
Int (9)
}
*/
Taken from zuodefeng's note