0

PHP considers this IF statement as true although the variable equals 0 NOT 'subjob'!

echo 'start';
$my_var = 0;
//Here, the result should skip the if BUT it doesn't: 
if($my_var == 'subjob'){
    echo $l_job_par_type;
}
echo 'end';
die();

The last result is:

start0end

Why is that?

Tariq
  • 2,853
  • 3
  • 22
  • 29
  • 2
    `'subjob'`, cast to a number, is `0`. Which is obviously equal to `0`. Use `===` instead. (I actually had to deal with this "feature" in my own code today XD) – Niet the Dark Absol Feb 21 '16 at 17:15
  • 1
    *"If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically."* - http://php.net/manual/en/language.operators.comparison.php – billyonecan Feb 21 '16 at 17:16
  • Ok, thanks guys. This is weird why this was the first time I have this issue! – Tariq Feb 21 '16 at 17:22

0 Answers0