0

I'm coding some PHP app and I'm receving some strange values from my code, example:

//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:

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 $i i will get wrong values but var_dump will show the RIGHT value. 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

2
  • 1
    where is $r defined, and what is it? Commented Sep 6, 2013 at 11:28
  • ah sorry pasted old one, that's not part of the code i just tried to copy $testvar to $r and didn't work. Commented Sep 6, 2013 at 11:31

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

1 Comment

oh yes my bad.... that leads me to another question for my code as $testval<$i will work only for $testval==$i. I think i will open a new question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.