I have this function from a shopping cart class I am trying to modify. I passing the product_id (hidden input) and an array using a form. I would like to modify the code to add the array value. What do I need to do to make it work?
here is the function:
function add(&$productid, $qty) {
/ add an item to the shopping cart and update the total price /
if (isset($productid)) {
setdefault($this->items[$productid], 0);
$this->items[$productid] += $qty;
}
}
Also what is the ampersand in the arguement doing?
Here is the part of the cart class if you needed to see this info as well.
class Cart {
var $items; / array of items /
var $total; / total of the cart /
function Cart() {
/* object constructor */
$this->init();
}
function init() {
/* this function is called to initialize (and reset) a shopping cart */
$this->items = array();
$this->total = 0;
}
function add(&$productid, $qty) {
/* add an item to the shopping cart and update the total price */
if (isset($productid)) {
setdefault($this->items[$productid], 0);
$this->items[$productid] += $qty;
}
}
function set(&$productid, $qty) {
/* set the quantity of a product in the cart to a specified value */
if (isset($productid)) {
$this->items[$productid] = (int) $qty;
}
}
Thx in advance,
Alex