生成字母和数字以创建跟踪代码

时间:2016-05-15 11:19:28

标签: php

我需要使用像a00000001这样的PHP生成跟踪代码,最多a99999999逐个生成,如果a来到a99999999b‍字母是开头的,例如a字母
跟踪代码的第一个字母从a开始到z,其他8 nmber从00000001开始到99999999

1 个答案:

答案 0 :(得分:1)

我想你想要这样的东西:

<?php
    $alpha='a';
    $num=1;
   /* put this in a function */
    $num=str_pad($num, 8, '0', STR_PAD_LEFT);
    if($num==99999999){
      $alpha++;
      $num=1;
    }
   /* function ends here */
    $alpha .=$num;
echo $alpha."<br />";

   /* call that function while incrementing so as to check the number has not reached 99999999 */
    $alpha++; //this increment must happen in the function
echo $alpha."<br />";

?>

输出:

a00000001
a00000002

根据需要增加$alpha,一旦达到a99999999,就会变为b00000001