auto increment alphanumeric characters php

穿精又带淫゛_ 提交于 2019-12-11 05:57:58

问题


Is is possible to auto increment an alphanumeric number with php so it looks like:

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

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

Cheers,


回答1:


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 />';
}


来源:https://stackoverflow.com/questions/5407429/auto-increment-alphanumeric-characters-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!