Php uses str_pad to automatically add 0 digits if the card number is not enough. str_pad card number _ PHP Tutorial

Source: Internet
Author: User
The str_pad card number is used by php to automatically fill in the number of digits below the number of digits based on str_pad. Php uses the str_pad method to automatically add 0 digits when the card number is insufficient. the str_pad function can help us implement the str_pad function in php () the function fills the string in php. based on str_pad, the function automatically fills in the number of digits that are not enough. The str_pad card number

The str_pad function can automatically fill in the blank digits in php to help us implement it. the str_pad () function fills the string with the specified length.

The str_pad () function fills the string with the specified length.
Syntax
Str_pad (string, length, pad_string, pad_type)

Parameters Description
String Required. Specifies the string to be filled.
Length Required. Specify the length of the new string. If the value is smaller than the length of the original string, no operation is performed.
Pad_string Optional. The specified string for filling. The default value is blank.
Pad_type

Optional. Specify the other side of the string to be filled.

Possible values:

  • STR_PAD_BOTH-fill in the two ends of the string. If it is not an even number, the right side will receive additional filling.
  • STR_PAD_LEFT-fill in the left side of the string.
  • STR_PAD_RIGHT-fill in the string to the right. This is the default one.

Example:

The code is as follows:

$ CardCount = 10;
$ Arr = array ();
For ($ I = 1; $ I <= $ cardCount; $ I ++ ){
$ StrCard = str_pad ($ I, 10, '0', STR_PAD_LEFT );
$ Arr [] = $ strCard;
}
Print_r ($ arr );


The output result is as follows:

The code is as follows:


Array ([0] => 0000000001 [1] => 0000000002 [2] => 0000000003 [3] => 0000000004 [4] => 0000000005 [5] => 0000000006 [6] => 0000000007 [7] => 0000000008 [8] => 0000000009 [9] => 0000000010)

I hope this article will help you with PHP programming.

The str_pad function in php can help us implement the padding function automatically. the str_pad () function fills the string...

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.