简体   繁体   中英

auto increment alphanumeric characters php

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,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM