j.smith1981 Posted November 4, 2010 Share Posted November 4, 2010 I am having trouble understanding what this means: foreach($_SESSION['cart'] as $product_id => $quantity) I look forward to any responses in advance. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 4, 2010 Share Posted November 4, 2010 http://php.net/manual/en/control-structures.foreach.php Quote Link to comment Share on other sites More sharing options...
wigpip Posted November 4, 2010 Share Posted November 4, 2010 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';} Quote Link to comment Share on other sites More sharing options...
j.smith1981 Posted November 5, 2010 Author Share Posted November 5, 2010 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! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.