我有一个变量$counter,返回以下整数:
4
Run Code Online (Sandbox Code Playgroud)
我想使用数字格式或类似格式使我的整数以这种格式显示:
000,000,004
Run Code Online (Sandbox Code Playgroud)
我该怎么办?
如果示例如何允许PHP计算0:
$a = "00001";
$b = "00005";
$total = $a + $b;
Run Code Online (Sandbox Code Playgroud)
预期结果是: 00006
包括并保持0000出现.
我试过但结果总是: 6
我想将我的数组变量格式化为十个以下的数字有前导零,所以:
$myArray=array(1,2,3,10,11,100);
Run Code Online (Sandbox Code Playgroud)
所以它是:
$myArray=array(01,02,03,10,11,100);
Run Code Online (Sandbox Code Playgroud)
这有一个简单的功能吗?
提前致谢.
我有来自数组的时间字符串,如果不存在10以下的整数值,我想加上前导零.例如我想要
this "8:10:12" to "08:10:12"
this "13:7:14" to "13:07:14"
this "13:25:6" to "13:25:06"
Run Code Online (Sandbox Code Playgroud)
我可以通过":"拆分一个非常混乱的代码,依此类推,但我想知道是否可以通过一行清理代码完成.如果单线无法做到,请回复.我会做那些凌乱的代码.
提前致谢..!
如果数字小于10,我想用两位数增加数字
这是我到目前为止所尝试的
$i = 1;
echo $i++;
Run Code Online (Sandbox Code Playgroud)
结果是1,2,3,4,5,6等等
然后我尝试添加条件
$i = 1;
if ($i++<10){
echo "0".$i++;
}else{
echo $i++;
}
Run Code Online (Sandbox Code Playgroud)
工作但跳过数字2,4,6,8等.
谁能告诉我正确的方法呢?
我试图得到for循环的结果如:00001, 00002, 00003,等但结果不显示0's:而是我得到:1, 2, 3,等等
这是代码:
$min = 00001;
$max = 00005;
for ($x = $min; $x <= $max; $x++) {
echo "$x ";
}
Run Code Online (Sandbox Code Playgroud) 我有从0到999的数字,并希望以给定的格式打印
0 : 000
1 : 001
2 : 002
.
.
.
.
11 : 011
99 : 099
.
.
111 : 111
999 : 999
Run Code Online (Sandbox Code Playgroud)
什么结束号是9999然后数字长度应该是4像(0000,0001,0022,0999等)
什么是最好的方法来做到这一点
如果数字小于 10,我想创建一个带有前导零的分页: < 07 08 09 10 11 >
我的分页输出类似的 HTML:
<div>
<a href="#"><</a>
<span>7</span>
<a href="#">8</a>
<a href="#">9</a>
<a href="#">10</a>
<a href="#">11</a>
<a href="#">></a>
</div>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用该preg_replace函数来捕获个位数并添加前导零,但我不知道如何保留该数字:
$r = preg_replace('/>[0-9]</', '>01<', $r);
return $r;
Run Code Online (Sandbox Code Playgroud)
我解决了这个问题,str_replace但这很丑陋:
$r = str_replace(array('>1<','>2<','>3<','>4<','>5<','>6<','>7<','>8<','>9<'), array('>01<','>02<','>03<','>04<','>05<','>06<','>07<','>08<','>09<'), $r);
Run Code Online (Sandbox Code Playgroud) php ×8
for-loop ×1
format ×1
formatting ×1
integer ×1
leading-zero ×1
math ×1
pagination ×1
preg-replace ×1
timestamp ×1