[英]Variable issue with PHP
I'm coding some PHP app and I'm receving some strange values from my code, example: 我正在编写一些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>";
will print at $i=9:
将以$i=9:
打印$i=9:
val 8 counter 9 bool
int(9) int(8) int(1) -8 comp
As you can see something very bad happened, if i try to subtract $testval from $ii will get wrong values but var_dump will show the RIGHT value. 如您所见,发生了非常糟糕的事情,如果我尝试从$ ii中减去$ testval将得到错误的值,但var_dump将显示RIGHT值。 Also first part of the second echo is missing and i don't know why. 第二回声的第一部分也丢失了,我也不知道为什么。
How do i fix or debug this to fix it? 我该如何解决或调试此问题以进行修复?
Thanks in advance 提前致谢
please try this: 请尝试以下操作:
echo "<br> again val ".$testval." y ".($i-$testval)." comp <br>";
if you forget the brackets it will happen something like this: 如果忘记括号,则会发生以下情况:
$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.