繁体   English   中英

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:打印$i=9:

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

如您所见,发生了非常糟糕的事情,如果我尝试从$ ii中减去$ testval将得到错误的值,但var_dump将显示RIGHT值。 第二回声的第一部分也丢失了,我也不知道为什么。

我该如何解决或调试此问题以进行修复?

提前致谢

请尝试以下操作:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM