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);}}