我需要使用给定格式的给定序列生成唯一的票号
C0000000001
C0000000002
C0000000003
C0000000004
C0000000005
C0000000006
C0000000007
C0000000008
C0000000009
C0000000010
C0000000011
答案 0 :(得分:0)
您可以尝试使用str_pad
<强>代码强>
$max = 9;
for($x = 1; $x <= 11; $x++){
echo 'C' .str_pad('', $max - strlen((string) $x), '0', STR_PAD_LEFT) . $x . "<br />";
}
<强>结果强>
C000000001
C000000002
C000000003
C000000004
C000000005
C000000006
C000000007
C000000008
C000000009
C000000010
C000000011