【发布时间】:2012-02-15 14:18:32
【问题描述】:
输入变量后,
PHP 代码:
$CartItem = array(
'itemID' => $itemID,
'ProductName' => $ProductName,
'Option' => $Option,
'Quantity' => $Quantity,
'Price' => $Price,
'Total' => $Total
);
setcookie('CartItem', $CartItem, null);
输出错误:
Warning: setcookie() expects parameter 2 to be string, array given in /Users/user/Sites/app/addtocart.php on line 46
【问题讨论】:
-
你真的不应该为此使用cookies。而是将购物车存储在
$_SESSION中,如果需要长期存储,请将其序列化到数据库中。有关示例,请参阅stackoverflow.com/questions/8128433/…。
标签: php arrays shopping-cart setcookie