I want to add multiple values into arrays, for same key. I have this code:
public function getOnlySellers()
{
$sellers[] = array();
foreach ($this->getProducts() as $product) {
$product_id = $product['product_id'];
$getseller = $this->getSellerbyProduct($product_id);
$sellers[$getseller] = $product_id;
}
return $sellers;
}
Here I have for example: seller 1 with values: 100 and 101 Seller 2 with values: 107
But on my code, on seller 1 for example, is showing only last value 101, but not both. What is wrong ?
And the call code:
$call = $this->cart->getOnlySellers();
foreach ($call as $seller => $products)
{
$show = "$show <br> $seller has value $products";
}
Thanks!
$sellersarray, you are overwriting any previous entry. You could append the new product_id instead.