user1711384 user1711384 - 7 months ago 11
PHP Question

Simple If else is not working

<?php
var_dump($isHoster); // prints int(0)

if ($isHoster == 'all')
$conditionsHoster = '0, 1';
else
$conditionsHoster = intval($isHoster);

var_dump($conditionsHoster); // prints string(4) "0, 1"
?>


What is going on?? Who can explain that?
This never happened to me...

Answer

0 == 'all' is true in php because php tries to convert 'all' to int and (int) 'all' is 0; you should write

if ($isHoster === 'all')