Jump to content

[SOLVED] multiple items in array


wmguk

Recommended Posts

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

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.