PHP Populating array with $variables
I'm 开发者_JAVA百科trying to create a basic shopping cart, having an issue with the product page allowing users to add more items to their cart then are in stock (I have code in place to prevent this on the view cart page, just not the view product page)
This is what I have so far;
for ($i = 0; $i < $numItem; $i++) {
extract($cartContent[$i]);
$subTotal += $price * $cartQuantity;
$cartLimiter[$itemNo => $cartQuantity];
Using an array so the position number becomes the item number and the cart quantity becomes the assigned value, however it doesn't seem to like it and throws out on the bottom line of code:
Parse error: syntax error, unexpected T_DOUBLE_ARROW, expecting ']'
Thanks
Change this:
$cartLimiter[$itemNo => $cartQuantity];
to:
$cartLimiter[$itemNo] = $cartQuantity;
$cartLimiter[$itemNo] = $cartQuantity;
$cartLimiter[$itemNo] = $cartQuantity;
精彩评论