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';}

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.