为什么我的PHP代码返回inf?
问题描述:
我有一个数学问题,我试图计算一组值的总和...当我尝试运行我的计算时,它只返回INF而不是数字...
I have a math problem where I am trying to calculate the total combination of values in a set... when I try and run my calculation it just returns INF instead of a number...
$tally = 1;
foreach ($output as $key => $er) {
$tally = $tally *(ord(strtolower($er)) - 96);
}
echo $tally;
答
如果您尝试回显一个数字并且不满意PHP给您 INF,这是因为PHP认为该数字是无限的,或者太大而无法存储在其内存中。
If when you try and echo a number and isntead PHP gives you "INF", it is because PHP thinks that the number is infinite, or too large to be stored in its memory.
您可以通过 echo is_infinite($ tally);