tags:

views:

31

answers:

2

I have written the following piece of code

if( (!isset($_SESSION['home'])) || (!isset($_SESSION['away'])) )

I assume this should check if each of these variables exist. I only show whats in the if statement if either of those variables dont exist.

But for some reason it is still showing the stuff inside the braces even though the variable 100% exists.

Is the code wrong? Thanks

+5  A: 

Then you need an 'AND' (&&) statement, not an 'OR' (||), if I understand correctly...

if( (!isset($_SESSION['home'])) && (!isset($_SESSION['away'])) )
Macmade
Its one or the other, only one will be present.I am stepping through a process where home is present, then unset but away is then present, then when away is unset, i want it to reappear.
Luke
Marco Ceppi
Actually, if the above is really what the OP wants, than you may even shorten this: `if (!isset($_SESSION['home'], $_SESSION['away']))`. That's some nice syntax sugar isset provides ,)
nikic
Luke
A: 

I think what you actually meant is:

if(!((!isset($_SESSION['home'])) || (!isset($_SESSION['away'])))){
    //code if at least one of those variables exists
}else {
    //the other thing
}
cypher