PHP中的数字反转未显示正确的输出 [英] Reverse of number in PHP not showing correct output
本文介绍了PHP中的数字反转未显示正确的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个程序来反转数字,但是每次将0
附加到结果之后.
I have made a program to reverse the number but every time 0
gets appended to the result.
$num = 675;
$rev = 0;
while($num > 0) {
$temp = $num % 10;
$rev = ($rev * 10) + $temp;
$num = (int) $num / 10;
}
echo $rev; //result is 5760
推荐答案
您的问题是这一行:
$num = (int) $num / 10;
与以下相同:
$num = ((int) $num) / 10;
因此它实际上不会强制转换结果.使用多余的括号:
so it doesn't actually cast the result. Use the extra parentheses:
$num = (int) ($num / 10);
这篇关于PHP中的数字反转未显示正确的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文