Reputation: 15
I'm trying to develop an online shop and when I try to list all my basket products, if I do
$basket = array(
'6512bd43d9caa6e02c990b0a82652dca' =>
array(
'id' => '11',
'quantity' => '51',
'price' => '0.28',
'stock' => '50',
'name' => 'Tomato',
'description' => 'u (140 gr aprox.) (1,99 â¬/Kg.)',
'discount' => '0',
'img' => '10.png',
'unique_id' => '6512bd43d9caa6e02c990b0a82652dca',
'total' => 14.28
),
'72b32a1f754ba1c09b3695e0cb6cde7f' =>
array(
'id' => '57',
'quantity' => '15',
'price' => '2.70',
'stock' => '15',
'name' => 'fish ',
'description' => 'tuna 500 gr',
'discount' => '0',
'img' => '57.png',
'unique_id' => '72b32a1f754ba1c09b3695e0cb6cde7f',
'total' => 40.5
)
);
if($basket)
{
echo "Basket:" . '<br/>';
print_r($basket);
echo '<br/>';
echo "Products:" . '<br/>';
foreach($basket as $product)
{
print($product);
echo '<br/';
}
}
This is the returned
Basket:
Array
(
[6512bd43d9caa6e02c990b0a82652dca] => Array
(
[id] => 11
[quantity] => 51
[price] => 0.28
[stock] => 50
[name] => Tomato
[description] => u (140 gr aprox.) (1,99 â¬/Kg.)
[discount] => 0
[img] => 10.png
[unique_id] => 6512bd43d9caa6e02c990b0a82652dca
[total] => 14.28
)
[72b32a1f754ba1c09b3695e0cb6cde7f] => Array
(
[id] => 57
[quantity] => 15
[price] => 2.70
[stock] => 15
[name] => fish
[description] => tuna 500 gr
[discount] => 0
[img] => 57.png
[unique_id] => 72b32a1f754ba1c09b3695e0cb6cde7f
[total] => 40.5
)
)
Productos:
Array ( [id] => 11 [quantity] => 51 [price] => 0.28 [stock] => 50 [name] => Tomato [description] => u (140 gr aprox.) (1,99 â¬/Kg.) [discount] => 0 [img] => 10.png [unique_id] => 6512bd43d9caa6e02c990b0a82652dca [total] => 14.28 )
57 [quantity] => 15 [price] => 2.70 [stock] => 15 [name] => fish [description] => tuna 500 gr [discount] => 0 [img] => 57.png [unique_id] => 72b32a1f754ba1c09b3695e0cb6cde7f [total] => 40.5 )
But, if I do
if($basket)
{
echo "Basket:" . '<br/>';
print_r($basket);
echo '<br/>';
echo "Products:" . '<br/>';
foreach($basket as $product)
{
print($product["name");
echo '<br/';
}
}
The returned is:
Basket:
Array ( [6512bd43d9caa6e02c990b0a82652dca] => Array ( [id] => 11 [quantity] => 51 [price] => 0.28 [stock] => 50 [name] => Tomato [description] => u (140 gr aprox.) (1,99 â¬/Kg.) [discount] => 0 [img] => 10.png [unique_id] => 6512bd43d9caa6e02c990b0a82652dca [total] => 14.28 ) [72b32a1f754ba1c09b3695e0cb6cde7f] => Array ( [id] => 57 [quantity] => 15 [price] => 2.70 [stock] => 15 [name] => fish [description] => tuna 500 gr [discount] => 0 [img] => 57.png [unique_id] => 72b32a1f754ba1c09b3695e0cb6cde7f [total] => 40.5 ) )
Products:
Tomato
I don't understand why it only shows the first item of the basket. What can I do to fix it?
Thanks!
Upvotes: 0
Views: 165
Reputation: 1379
You are doing correct. But when you miss the close the <br/
tag then data rendered but not visible on your end.
Products:
10
Upvotes: 0
Reputation: 363
You're already doing it right, except to close the bracket after <br/
.
It should be <br/>
Upvotes: 1