Question

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?

Was it helpful?

Solution

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');

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top