user3649115 user3649115 - 3 months ago 6
PHP Question

Serial number with alphabetes and numbers

Need PHP alphanumeric count that starts from A001 and goes uptill ZZ999

It starts from A001 and goes on like A002, A003 .....

and after A999 - it changes to B001 and so on till ZZ999

my code is work for only A999 to Z999.

how can this be done ... ?

Can anyone here help me out ..?

thanks in advance !!

foreach (range('A', 'Z') as $letter) {
foreach (range(1, 100) as $number) {
echo $letter.str_pad($number, 3, '0', STR_PAD_LEFT)."\n";
}
}

Answer

Try like this

for ($letter = 'A'; $letter !== 'AAA'; $letter++){
    foreach (range(1, 999) as $number) {
            echo $letter.str_pad($number, 3, '0', STR_PAD_LEFT)."\n";
    }
}