小智 7
你可以查看str_pad
在你的情况下,它将是这样的:
str_pad('1', 6, '0', STR_PAD_LEFT);
Run Code Online (Sandbox Code Playgroud)
function padWithZeros($s, $n) {
return sprintf("%0" . $n . "d", $s);
}
Run Code Online (Sandbox Code Playgroud)
其中$ n是您想要的零数,例如:
echo padWithZeros("1", 6);
Run Code Online (Sandbox Code Playgroud)
将数字1填充为五个零等于六个位置