title: Using PHP - check if shopping cart is empty and, if so, display message
body: <p>I'm new to php so I've struggled through each step of this assignment. I've hit a wall with this final step. I've built a simple shopping cart using only PHP (per the instructions). The index.php page contains all the items as well as a checkout button that redirects to the checkout.php page. If the user clicks this "checkout" button before items have been added to their cart, I need to display "Your cart is empty" message on the checkout page. I'm assuming I need to do the check on the checkout.php file. I've attempted it more than a dozen times without luck. Help is appreciated. </p>
  
  <p>I'm including my attempted code on the checkout.php file </p>
  
  <pre><code>&lt;?php
  
  require_once('session_util.php'); 
  
  if(isset($_SESSION[SHOPPING_CART]) &amp;&amp; empty($_SESSION[SHOPPING_CART])) {
      echo 'Your shopping cart is empty.';
  }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;title&gt;Form 1&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="style.css"&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;main&gt;
      &lt;h2&gt;Checkout&lt;/h2&gt;
      &lt;table id="cart"&gt;
          &lt;?php
          // This is where session starts
          $itemArray = $_SESSION[SHOPPING_CART]-&gt;getItemArray();
          foreach ($itemArray as $item) {
              $name = $item-&gt;getName();
              $price = number_format($item-&gt;getPrice(), 2);
  
              echo "&lt;tr&gt;
                      &lt;th&gt;$name&lt;/th&gt;
                      &lt;th&gt;$$price&lt;/th&gt;
                    &lt;/tr&gt;";
          }
  
          // you will get these from the shopping cart, not a specifc item
          $subTotal = number_format($_SESSION[SHOPPING_CART]-&gt;subTotal(), 2);
          $tax = number_format($_SESSION[SHOPPING_CART]-&gt;addTax(), 2);
          $total = number_format($_SESSION[SHOPPING_CART]-&gt;getTotal(), 2);
  
          // Display calculated subtotal, tax, and total.
          ?&gt;
          &lt;?php
          echo "
              &lt;table id='total'&gt;
              &lt;tr&gt;&lt;td&gt;SubTotal &amp;nbsp $$subTotal&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Tax &amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp $$tax&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td&gt;Total &amp;nbsp &amp;nbsp &amp;nbsp &amp;nbsp $$total&lt;/tr&gt;&lt;/td&gt;
              &lt;/table&gt;
              ";
          ?&gt;
      &lt;/table&gt;
      &lt;form id="keep_shopping" method="post" action="index.php"&gt;
          &lt;input id="submit" type="submit" class="keep_shopping" name="keep_shopping" value="Keep Shopping"&gt;
      &lt;/form&gt;
      &lt;form id="empty_cart" method="post" action="clear_cart.php"&gt;
          &lt;input id="submit" type="submit" class="empty_cart" name="empty_cart" value="Empty Cart"&gt;
      &lt;/form&gt;
  &lt;/main&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Edits and Infromation as asked in comment: <br>
  <code>enter code here</code>session_start() is located in a separate file - session_util.php - and this file is required at the top of all other assignment files.<br><br>
  Also, when I do a var_dump on <code>$_SESSION[SHOPPING_CART]</code>; I get the following: </p>
  
  <blockquote>
    <p>object(ShoppingCart)#11 (1) { ["itemArray":"ShoppingCart":private]=>
    array(0) { } } </p>
  </blockquote>