PHP integrer 从整数的开头删除零

PHP integrer removing zero from the start of integer

从字符串中删除前面的零

000001 to 000010

它存储以下值

00001, 2, 3, 4, 5, 6, 7, 8, 8, 10

但我想要这样的东西。

00001, 00002, 00003, 00004, 00005, 00006, 00007, 00008, 00009, 000010

算法正在从一开始就删除那些零。 请告诉我该怎么做。

这个很简单!试试这个:

<?php

$num = 5;
echo str_pad($num, 6, '0', STR_PAD_LEFT);

输出 000005

看这里https://3v4l.org/0Fgdp

如果没有固定的零,则:

str_pad($your_no, $total_no_of_digits, $string_to_append, STR_PAD_LEFT);

否则,您可以使用关联数组定义零个数,然后使用 str_pad()