Re: multi dimensional array producing a parse error

From: Date: Tue, 16 Oct 2001 19:01:48 +0000
Subject: Re: multi dimensional array producing a parse error
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-71251@lists.php.net to get a copy of this message
At 11:20 AM -0700 10/16/01, Sheila Myers wrote:
I'm struggling with using a multidimensional array in my shopping cart class. Can anyone tell me why this code is generating a parse error at the indicated line? Thanks, Sheila Class Cart { var $items = array("productid"=>'', "details"=>array( "price"=>'', "quantity"=>'', "shipping"=>'', "tax"=>'', "desc"=>'', "note"=>'') ); var $product_total; var $shipping_total; var $tax_total; var $cart_id; function add($sell_price,$qty,$shipping,$tax,$productid,$short_desc,$note) { /* add an item to the shopping cart and update the total price */ if (isset($this->items[$productid])) //if it is already in the cart, don't add a new occurence, just update the total quantity
{              	$this->items[$productid]["quantity"] += $qty;
} else { $this->items["productid"]=>$productid; <<<==================this is the line reporting the parse error
Easy; don't use the => construct here (and in the following lines). That's only for use in the array() function. Just use $this->items["productid"] = $productid; here and in the lines below. -steve
$this->items[$productid]["price"]=>$sell_price; $this->items[$productid]["quantity"]=>$qty; $this->items[$productid]["shipping"]=>$shipping; $this->items[$productid]["tax"]=>$tax; $this->items[$productid]["desc"]=>$short_desc; $this->items[$productid]["note"]=>$note; $this->product_total = $this->product_total += $sell_price; $this->shipping_total = $this->shipping_total += $shipping; } var_dump $this->items; //debugging } //end add
-- +--------------- my people are the people of the dessert, ---------------+ | Steve Edberg sbedberg@ucdavis.edu | | University of California, Davis (530)754-9127 | | Programming/Database/SysAdmin http://pgfsun.ucdavis.edu/ | +---------------- said t e lawrence, picking up his fork ----------------+

« previous php.general (#71251) next »