bleustreak12 Posted March 19, 2012 Share Posted March 19, 2012 will this code check if value is null if($_SESSION["cart"] != null) Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/ Share on other sites More sharing options...
freelance84 Posted March 19, 2012 Share Posted March 19, 2012 You could do: if(!empty($_SESSION["cart"])) Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/#findComment-1328974 Share on other sites More sharing options...
bleustreak12 Posted March 19, 2012 Author Share Posted March 19, 2012 You could do: if(!empty($_SESSION["cart"])) empty function takes 0 also as empty, what if my $_SESSION["cart"]=0 Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/#findComment-1328982 Share on other sites More sharing options...
freelance84 Posted March 19, 2012 Share Posted March 19, 2012 Ah true, then you could use isset if(isset($_SESSION['cart'])) { //do something } Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/#findComment-1328984 Share on other sites More sharing options...
Muddy_Funster Posted March 19, 2012 Share Posted March 19, 2012 will this code check if value is null if($_SESSION["cart"] != null) it's one line of code, you would have been quicker testing it yourself if(strlen(trim($_SESSION['cart'])) >= 1) could also be an option Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/#findComment-1328985 Share on other sites More sharing options...
AyKay47 Posted March 19, 2012 Share Posted March 19, 2012 I like is_null But for a session value you can use isset Quote Link to comment https://forums.phpfreaks.com/topic/259247-will-this-code-check-if-value-is-null/#findComment-1329001 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.