gpt4 book ai didi

PHP计算变量值前加0

转载 作者:可可西里 更新时间:2023-11-01 00:02:36 26 4
gpt4 key购买 nike

如何让PHP计算出现0的例子:

$a = "00001";
$b = "00005";

$total = $a + $b;

预期结果是:00006

Including and keep 0000 出现。

我试过了,但结果总是:6

最佳答案

只需做正常的数学运算,然后在末尾的前面加回零即可:

$a = "00001";
$b = "00005";

$total = $a + $b;
$total = sprintf("%05d", $total );

$total = str_pad($total , 5, "0", STR_PAD_LEFT);

关于PHP计算变量值前加0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23245727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com