方法一

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 />';
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
  • 2021-11-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-27
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
相关资源
相似解决方案