jeudi 7 janvier 2016

PHP strange situation in IF and Switch statment

I'm encountering a very strange situation while working with IF and Switch statements in PHP. Can anyone explain why the IF condition below is coming true and not executing ELSE block. Same is the case with Switch statement, it is not executing the default block.

Thank you for your time :)

$error = TRUE;

if ($error == FALSE OR $error == 'stringValue') {
  echo 'Inside IF';
} else {
  echo 'Inside ELSE';
}

switch($error){
    case FALSE:
    case 'stringValue':
        echo 'Inside First';
        break;

    default:
        echo 'Inside Default';
        break;
}

Aucun commentaire:

Enregistrer un commentaire