Php-Arrays function-array_pad-fill the array with values to the specified length

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.