Cart Content Snippet

<nav> <ul> <li><a href="home.php">Home</a></li> <li><a href="products.php">Products</a></li> <li><a href="viewcart.php"> View Cart <?php //cart session contained an array of items in the cart if(isset($_SESSION['cart'])) {$cart = $_SESSION['cart']; //counts all the values of an array $cartwithfrequency = array_count_values($cart); //calculate the sum of values in an array $totalcart = array_sum($cartwithfrequency); echo " - (" . $totalcart . ")" ;} ?></a></li> <li><a href="about.php">About Us</a></li> </ul> </nav>
Displaying total number of items in cart at a given time in PHP

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.