Very strange behaviour in PHP -


this question has answer here:

i have code:

$test = 0; if ($test == "on"){     echo "true"; } 

result of code be:

true 

why??? version of php: 5.4.10.

if compare number string or comparison involves numerical strings, each string converted number , comparison performed numerically. these rules apply switch statement. type conversion not take place when comparison === or !== involves comparing type value.

$test = 0; if ($test === "on"){     echo "true"; } 

php convert string number compare. using ===, compare value type of data.

var_dump(0 == "a"); // 0 == 0 -> true var_dump("1" == "01"); // 1 == 1 -> true var_dump("10" == "1e1"); // 10 == 10 -> true var_dump(100 == "1e2"); // 100 == 100 -> true 

docs


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -