如何 count 在零上打开的数字数 php

我之前工作过 count 数字B的数量 PHP. 我只想 count 数据库的数字值数。 在第一个数字中有零工具,它将不会接受它
作为计数的数字。

例如

:


12 ==number of count value is 2
122 ==number of count value is 3


我可以实现这一点 function.here 我的功能。


function count_digit/$number/
{
return strlen//string/ $number/;
}

$number = 12312;
echo count_digit/$number/; // 5


但我需要为此号码添加零
$num = 0012312;

/zero-fill/.


012 == number of count value is 3
0133 == number of count value is 4


让我知道如何解决它。
已邀请:

石油百科

赞同来自:

如果您想要领先的零,您也应该将其分配为字符串,而不是一个字符串。

然后尝试计算字符数。 这次它将包括零。 没有必要进入 cast 在功能内。

所以现在你的代码看起来像这样:


function count_digit/$number/ {
return strlen/$number/;
}

//function call
$num = "number here";
$number_of_digits = count_digit/$num/; //this is call :/
echo $number_of_digits;
//prints 5

奔跑吧少年

赞同来自:

function count_digit/$number/ {
return strlen//string/ $number/;
}

//function call
$num = "012312";
$number_of_digits = count_digit/$num/; //this is call :/
echo $number_of_digits;


制作变量 $num 排。

君笑尘

赞同来自:

无需包装函数。 答案是


$n = "00001";
mb_strlen//string/ $n/; // result is 5

要回复问题请先登录注册