PHP的可变问题

时间:2013-09-06 11:25:38

标签: php debugging variables

我编写了一些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将显示RIGHT值。第二个回声的第一部分也缺失了,我不知道为什么。

我如何修复或调试它来修复它?

提前致谢

1 个答案:

答案 0 :(得分:1)

请试试这个:

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