How do i add items into a multidimensional array? Basically i am making an application which calculates what people are buying in a suppermarket and how much of it.
Sue buys 2 tubs of butter and 1. toothpaste
John buys 1 peach and 1 banana.
I think the array would look something like this
$sue[butter] = array();
$sue[butter][] = 2;
$sue[toothpaste] = array();
$sue[toothpaste][] = 1;
$john[peach] = array();
$john[peach][] = 1;
$john[banana] = array();
$john[banana][] = 1;
My current code can only record the item and the item quantity.
public $items = array();
public function AddItem($product_id)
{
if (array_key_exists($product_id , $this->items))
{
$this->items[$product_id] = $this ->items[$product_id] + 1;
} else {
$this->items[$product_id] = 1;
}
}
I just dont know how to put this inside an array for each person.
Thanks!