PHP 的变量问题


Variable issue with PHP

我正在编写一些PHP应用程序,并且从我的代码中接收了一些奇怪的值,例如:

//Loop here lot of intval because i tried a lot of things
$testval=intval(intval($i/$dayspromo[$key])*$dayspromo[$key]);
echo "<br> val $testval counter $i bool<br>";
var_dump($i);
var_dump($testval);
var_dump($i-$testval);


 echo "<br> again val ".$testval." y ".$i-$testval." comp <br>";

将在$i=9:打印

val 8 counter 9 bool
int(9) int(8) int(1) -8 comp 

正如你所看到的,发生了一些非常糟糕的事情,如果我试图从$i中减去$testval,我会得到错误的值,但var_dump会显示正确的值。第二个回声的第一部分也丢失了,我不知道为什么。

如何修复或调试此问题以修复它?

提前致谢

请尝试以下操作:

echo "<br> again val ".$testval." y ".($i-$testval)." comp <br>";

如果您忘记了括号,它将发生如下情况:

$string = "hello world"; // you have a string
$tmp = $string - 10; // substract 10 from string
// string will be converted to int and this is zero
// zero minus 10 is -10