bleustreak12 Posted March 19, 2012 Share Posted March 19, 2012 will this code check if value is null if($_SESSION["cart"] != null) 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"])) 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 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 } 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 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 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
Archived
This topic is now archived and is closed to further replies.