Frage

I want to check if multiple conditions are true/false with php. So I have

$a = 'hello';

In the below I expect to return false as a does = hello

var_dump(($a !== 'hello'));
bool(false)

this works as expected,

however If I try and ad an or in as shown below it returns true.

var_dump(($a !== 'hello')||($a !== 'bye'));
bool(true)

Why is this and how can I structure this so that I get false?

War es hilfreich?

Lösung

You need to use AND. You check if $a isn't hello OR if $a isn't bye. The second one returns true.

var_dump($a !== 'hello' && $a !== 'bye');

Andere Tipps

Because $a !== 'bye'...since it is hello

$a isn't 'hello' OR $a isn't 'bye'

Well, it isn't 'bye' because it's 'hello'. Therefore, the test is true

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top