2014-11-03 58 views
-2

解析錯誤:語法錯誤,意外';'在C:\ XAMPP \ htdocs中\車\ ADMIN \ addtocart.php上線13找不到以下錯誤

這裏是我的代碼,

<?php 
if(isset($_POST['id'])){ 
     $pid=$_POST['id']; 
     $wasFound=false; 
     $i=0; 
     if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1){ 
      $_SESSION["cart_array"]=array(0=>array("item_id"=>$pid,"quantity"=>1)); 
     }else{ 
      foreach($_SESSION["cart_array"] as $each_item){ 
       $i++; 
       while(list($key,$value)=each($each_item)){ 
       if($key=="item_id" && $value==$pid){ 
        array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$pid,"quantity"=>$each_item['quantity']+1)); 
        $wasFound=true; 
       } 
      } 
     } 
     if($wasFound==false){ 
      array_push($_SESSION["cart_array"],array("item_id"=>$pid,"quantity"=>1)); 
     } 
    } 
    header("location:cart.php"); 
    exit(); 
} 
?> 
+1

你缺少a)在語句結尾 – Haris 2014-11-03 09:15:34

+0

你缺少a)在使用'array_splice'的語句末尾 – 2014-11-03 09:17:20

+0

請在運營商之間使用空格。閱讀沒有空格的代碼是很痛苦的。有關如何格式化代碼的指南,請參見[這裏](http://docs.typo3.org/flow/TYPO3FlowDocumentation/stable/TheDefinitiveGuide/PartV/CodingGuideLines/PHP.html#php-code-formatting)。 – tyteen4a03 2014-11-03 09:17:32

回答

-1

你下面一行錯過最後的右括號 ')'

array_splice($_SESSION["cart_array"],$i-1,1,array(array("item_id"=>$pid,"quantity"=>$each_item['quantity']+1)));