wmguk Posted April 21, 2009 Share Posted April 21, 2009 Hey, I'm using a cart system and I'm changing the code quite a lot to handle the item and the price... I click a link <td><a href=cart.php?action=add&id=$name&cost=$cost>Add</a></td> which goes to: if ($action=="add") { if ($cart) { $cart .= ','.$id.":".$cost; } else { $cart = $id; } and then when i try to see whats in the cart i use: <? $cart = $_SESSION['cart']; if ($cart) { $items = explode(',',$cart); $contents = array(); foreach ($items as $item) { $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; echo $item."<br>"; }} ?> but i dont get to see the cost, is there a way of using more than one variable in an array? Link to comment https://forums.phpfreaks.com/topic/155108-solved-multiple-items-in-array/ Share on other sites More sharing options...
wmguk Posted April 21, 2009 Author Share Posted April 21, 2009 ah ok, I used list... list($name, $cost) = explode(":", $item); echo $name." - ".$cost."<br>"; Link to comment https://forums.phpfreaks.com/topic/155108-solved-multiple-items-in-array/#findComment-815928 Share on other sites More sharing options...
wmguk Posted April 21, 2009 Author Share Posted April 21, 2009 is there anyway to add the $cost together to create a total? Link to comment https://forums.phpfreaks.com/topic/155108-solved-multiple-items-in-array/#findComment-815931 Share on other sites More sharing options...
wmguk Posted April 21, 2009 Author Share Posted April 21, 2009 nevermind.... $total += $cost ; I'm going home now Link to comment https://forums.phpfreaks.com/topic/155108-solved-multiple-items-in-array/#findComment-815933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.