php - Switch condition evaluates incorrectly on zero -
i trying piece of code this:
$event = 0; switch ($event) { case 'content': echo "/content"; break; case 'start': echo "/start"; break; default : echo "not available"; break; } this code prints /content when executed, so... 0 (zero, integer, assigned $event variable) being evaluated 'content'. why?
this happening
0 == 'content' php tries cast string content integer. since content doesnt equal int, defaults 0.
resulting in:
0 == 0
Comments
Post a Comment