方法一
for ($i=0; $i<100; $i++) { $index = sprintf('%04d', $i); echo $index.'<br />'; }
方法二
for ($i=0; $i<100; $i++) { $index = str_pad($i, 4, 0, STR_PAD_BOTH); // 默认:STR_PAD_RIGHT echo $index.'<br />'; }