hance2105 Posted June 21, 2013 Share Posted June 21, 2013 hello guys, y am i having an error on this line of code <?php $cartItemCount = count($_SESSION['cart']); ?> do i need to define the 'cart'? how i do it if need be? please Link to comment https://forums.phpfreaks.com/topic/279416-why-error-on-line/ Share on other sites More sharing options...
boompa Posted June 21, 2013 Share Posted June 21, 2013 $_SESSION['cart'] = array(); or if (isset($_SESSION['cart'])) $cartItemCount = count($_SESSION['cart']); else $cartItemCount = 0; or, using the ternary operator $cartItemCount = (isset($_SESSION['cart']) ? count($_SESSION['cart']) : 0; Link to comment https://forums.phpfreaks.com/topic/279416-why-error-on-line/#findComment-1437198 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.