Jump to content
Killersites Community
Sign in to follow this  
makamo66

Null session array condition not met until page is refreshed

Recommended Posts

When I use the following code, it doesn't print out "else if test" until after I refresh the page.

unset($_SESSION["product"]);

if ( !empty($_SESSION["product"]) && ($_SESSION["product"] != NULL)) {
echo "if test";
} else if {
echo "else if test";
}

When I use:

var_dump($_SESSION["product"]);

It shows:

array(0) { } 
 

Share this post


Link to post
Share on other sites

The code didn't actually make the call to unset the variables until after the not empty conditional was asked. I was misled because var_dump still printed out an empty session array. Once I changed the order of my code, it worked. 
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×