PHP implementation ID Self-increment and specify number of digits

Source: Internet
Author: User
This article introduces the content of the PHP implementation ID self-increment and specify the number of bits, has a certain reference value, now share to everyone, the need for friends can refer to

In the development process often encountered such a folding requirements:

The ID value is self-increment and the length is 7 bits. Not enough in front with 0 to be padded.

With Hugh Implementation:

Mysql

ID char (7) NOT null default ' 0000000 ';

Common Methods for PHP setup

/** * @param $id * @return string|void */protected function Isnumauto ($id) {    if (strlen ($id) > 7) {        $this->_j son[' msg '] = ' id greater than 7 bits, does not meet the requirements ';       Return Self::alertjson ($this->_json);    }    if (strlen ($id) < 7) {         $newid = sprintf ("%07d", Intval ($id) + 1);          if (strlen ($NEWID) <= 7) {              return $newid;          } else {             $this->_json[' msg '] = ' ID is greater than 7 bits, does not meet the requirements ';              Return Self::alertjson ($this->_json);}}   

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.