Nasıl çok boyutlu bir diziye ürün ekleyebilirim? Temelde i insanlar çok onun bir suppermarket ve nasıl satın aldıkları hesaplayan bir uygulama yapıyorum.
Sue buys 2 tubs of butter and 1. toothpaste
John 1 şeftali ve 1 muz satın alır.
Ben dizi bu gibi bir şey düşünüyorum
$sue[butter] = array();
$sue[butter][] = 2;
$sue[toothpaste] = array();
$sue[toothpaste][] = 1;
$john[peach] = array();
$john[peach][] = 1;
$john[banana] = array();
$john[banana][] = 1;
Benim şu anki kod yalnızca öğeyi ve madde miktarı kaydedebilirsiniz.
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;
}
}
Ben sadece her kişi için bir dizi içinde bu koymak için nasıl bilmiyorum.
Teşekkürler!