Maison >développement back-end >tutoriel php > php购物车有关问题

php购物车有关问题

WBOY
WBOYoriginal
2016-06-13 12:49:32991parcourir

php购物车问题

<?php<br />
  include ('book_sc_fns.php');<br />
  // The shopping cart needs sessions, so start one<br />
  session_start();<br />
<br />
  @$new = $_GET['new'];<br />
<br />
  if($new) {<br />
    //new item selected<br />
    if(!isset($_SESSION['cart'])) {<br />
      $_SESSION['cart'] = array();<br />
      $_SESSION['items'] = 0;<br />
      $_SESSION['total_price'] ='0.00';<br />
    }<br />
<br />
    if(isset($_SESSION['cart'][$new])) {<br />
      $_SESSION['cart'][$new]++;<br />
    } else {<br />
      $_SESSION['cart'][$new] = 1;<br />
    }<br />
<br />
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />
    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />
  }<br />
<br />
  if(isset($_POST['save'])) {<br />
    foreach ($_SESSION['cart'] as $isbn => $qty) {<br />
      if($_POST[$isbn] == '0') {<br />
        unset($_SESSION['cart'][$isbn]);<br />
      } else {<br />
        $_SESSION['cart'][$isbn] = $_POST[$isbn];<br />
      }<br />
    }<br />
<br />
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);<br />
    $_SESSION['items'] = calculate_items($_SESSION['cart']);<br />
  }<br />
<br />
  do_html_header("Your shopping cart");<br />
<br />
  if(($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {<br />
    display_cart($_SESSION['cart']);<br />
  } else {<br />
    echo "<p>There are no items in your cart</p><hr/>";<br />
  }<br />
<br />
  $target = "index.php";<br />
<br />
  // if we have just added an item to the cart, continue shopping in that category<br />
  if($new)   {<br />
    $details =  get_book_details($new);<br />
    if($details['catid']) {<br />
      $target = "show_cat.php?catid=".$details['catid'];<br />
    }<br />
  }<br />
  display_button($target, "continue-shopping", "Continue Shopping");<br />
<br />
  // use this if SSL is set up<br />
  // $path = $_SERVER['PHP_SELF'];<br />
  // $server = $_SERVER['SERVER_NAME'];<br />
  // $path = str_replace('show_cart.php', '', $path);<br />
  // display_button("https://".$server.$path."checkout.php",<br />
  //                 "go-to-checkout", "Go To Checkout");<br />
<br />
  // if no SSL use below code<br />
  display_button("checkout.php", "go-to-checkout", "Go To Checkout");<br />
<br />
  do_html_footer();<br />
?><br />


代码中的$_SESSION['cart'][$new]是什么意思,为什么要这样子做?

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn