1

I am looking for a way to convert a 1-5 digit int to a 5 digit alphanumeric number incrementally.

Example

for($i=0; $i<41; $i++){
    echo convert_i_to_alphanumeric($i);
}

OUTPUT//

00001 00002 00003 00004 00005 00006 00007 00008 00009 0000A 0000B 0000C 0000D 0000E 0000F 0000G 0000H 0000I 0000J 0000K 0000L 0000M 0000N 0000O 0000P 0000Q 0000R 0000S 0000T 0000U 0000V 0000W 0000X 0000Y 0000Z 00010 00011 00012 00013 00014 ...

4

1 回答 1

8

PHP 有一个可以使用 的base_convert函数。

base_convert($i,10,36)

要获得您拥有的填充格式,只需添加一个strtoupperstrpad

function convert_i_to_alphanumeric($digit) {
    return str_pad(strtoupper(base_convert($digit,10,36)),5,"0",STR_PAD_LEFT);
}
于 2013-05-09T20:14:49.337 回答