title: Access Cart Session Values Globally
body: <p>This is my cart Code where I have kept all Values into global cart session array.
  Here is my code:</p>
  
  <pre><code>$cartOutput = "";
  $cartTotal = "";
  $pp_checkout_btn = '';
  $product_id_array = '';
  if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) {
      $cartOutput = "&lt;h2 align='center'&gt;Your shopping cart is empty&lt;/h2&gt;";
  } else {
      // Start PayPal Checkout Button
      //$pp_checkout_btn .= '&lt;form action="https://www.paypal.com/cgi-bin/webscr" method="post"&gt;
      //&lt;input type="hidden" name="cmd" value="_cart"&gt;
      //&lt;input type="hidden" name="upload" value="1"&gt;
      //&lt;input type="hidden" name="business" value="you@youremail.com"&gt;';
      // Start the For Each loop
      $i = 0; 
      foreach ($_SESSION["cart_array"] as $each_item) { 
          $item_id = $each_item['item_id'];
          $sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
          while ($row = mysql_fetch_array($sql)) {
              $product_name = $row["product_name"];
              $price = $row["price"];
              $details = $row["details"];
          }
          $pricetotal = $price * $each_item['quantity'];
          $cartTotal = $pricetotal + $cartTotal;
          //setlocale(LC_MONETARY, "en_US");
          //$pricetotal = money_format("%10.2n", $pricetotal);
          // Dynamic Checkout Btn Assembly
          $x = $i + 1;
          $pp_checkout_btn .= '&lt;input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '"&gt;
          &lt;input type="hidden" name="amount_' . $x . '" value="' . $price . '"&gt;
          &lt;input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"&gt;  ';
          // Create the product array variable
          $product_id_array .= "$item_id-"."$product_name".$each_item['quantity'].","; 
  
  
          // Dynamic table row assembly
          $cartOutput .= "&lt;tr&gt;";
          $cartOutput .= '&lt;td&gt;&lt;a href="product.php?id=' . $item_id . '"&gt;' . $product_name . '&lt;/a&gt;&lt;br /&gt;&lt;img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="40" height="52" border="1" /&gt;&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;' . $details . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;Rs ' . $price . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;&lt;form action="cart.php" method="post"&gt;
          &lt;input name="quantity" onkeypress="return onlyNos(event,this);" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /&gt;
          &lt;input name="adjustBtn' . $item_id . '" type="submit" value="change" /&gt;
          &lt;input name="item_to_adjust" type="hidden" value="' . $item_id . '" /&gt;
          &lt;/form&gt;&lt;/td&gt;';
          //$cartOutput .= '&lt;td&gt;' . $each_item['quantity'] . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;' . $pricetotal . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;&lt;form action="cart.php" method="post"&gt;&lt;input name="deleteBtn' . $item_id . '" type="submit" value="X" /&gt;&lt;input name="index_to_remove" type="hidden" value="' . $i . '" /&gt;&lt;/form&gt;&lt;/td&gt; ';
          $cartOutput .= '&lt;/tr&gt;';
          $i++; 
      } 
  </code></pre>
  
  <p>Now this is my cart array which I use to render it on my cart page.
  Now how can i fetch values from cart array.</p>