Jump to content

foreach question in an array of $_SESSION


j.smith1981

Recommended Posts

foreach($_SESSION['cart'] as $product_id => $quantity)

 

would appear as

foreach($_SESSION['cart'] as $product_id => $quantity) 
{ do something here; }

 

It's a loop through the array $_SESSION['cart']. product_id is the 'Key' and 'quantity' is the Value.

 

So usually with the foreach loop you access each value ($quantity) and do something with it, like compare it or add to database or whatever, echo it.

 

example:

 

foreach($_SESSION['cart'] as $product_id => $quantity) 
{ if($quantity < 500) { echo 'that is below reserve price';}

 

foreach($_SESSION['cart'] as $product_id => $quantity)

 

would appear as

foreach($_SESSION['cart'] as $product_id => $quantity) 
{ do something here; }

 

It's a loop through the array $_SESSION['cart']. product_id is the 'Key' and 'quantity' is the Value.

 

So usually with the foreach loop you access each value ($quantity) and do something with it, like compare it or add to database or whatever, echo it.

 

example:

 

foreach($_SESSION['cart'] as $product_id => $quantity) 
{ if($quantity < 500) { echo 'that is below reserve price';}

 

 

So there would be many productid's and just 1 qty for each product as yes with what I have as the rest of the program, I thought that was it, just was very late and was tired and probably wasnt concentrating properly.

 

Thanks ever so much!

 

Going to try and output those aswell, just to see what I can do with it, ace thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.