开发者

auto increment alphanumeric characters php

开发者 https://www.devze.com 2023-02-19 01:12 出处:网络
Is is possible to auto increment an alphanumeric number with php so it looks like开发者_Python百科:

Is is possible to auto increment an alphanumeric number with php so it looks like开发者_Python百科:

AB001
AB002
...
...
BA001
...
...
ZZ001

This code will then need to be added to mysql, I was thinking a varchar(5).

Cheers,


Try it and see

$x = 'AA998';
for($i = 0; $i < 10; $i++) {
    echo $x++,'<br />';
}

EDIT

Reverse of letters and digits

$x = '000AY';
for($i = 0; $i < 10; $i++) {
    echo $x++,'<br />';
}

or reversal after ZZ999

$x = 'ZZ998';
for($i = 0; $i < 10; $i++) {
    $x++;
    if (strlen($x) > 5)
        $x = '000AA';
    echo $x,'<br />';
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号