<?php $var=sprintf("%02d", 2);//生成2位数,不足前面补0 echo $var;//结果为02 ?>
參考:https://blog.csdn.net/shaobaojie/article/details/17268627