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. Link to comment https://forums.phpfreaks.com/topic/217788-foreach-question-in-an-array-of-_session/ 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 Link to comment https://forums.phpfreaks.com/topic/217788-foreach-question-in-an-array-of-_session/#findComment-1130449 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';} Link to comment https://forums.phpfreaks.com/topic/217788-foreach-question-in-an-array-of-_session/#findComment-1130457 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! Link to comment https://forums.phpfreaks.com/topic/217788-foreach-question-in-an-array-of-_session/#findComment-1130612 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.