Adding a "Item" from array to a cart

Hi all,
I’m trying to make a php shopping cart, for my task I have been told to use arrays (I know it should be in a database), however, at current I have all the products in an array and within a table and links for adding to a cart.

My only issue is that I have no idea how to add the items to a “cart”, baring in mind these items need to remain temporarily stored as I would like them to be used in a summary screen upon clicking Submit.

[php]<?php
$Item1 = array(‘SKU’=>test1, ‘name’=>ProductTest1, ‘Price’=>10.00);
$Item2 = array(‘SKU’=>test2, ‘name’=>ProductTest2, ‘Price’=>11.00);
$Item3 = array(‘SKU’=>test3, ‘name’=>ProductTest3, ‘Price’=>12.00);

?>

SKU Name Price Action
<?php echo $Item1[SKU]; ?> <?php echo $Item1[name]; ?> <?php echo '£'. number_format($Item1[Price],2); ?> Add To Cart
<?php echo $Item2[SKU]; ?> <?php echo $Item2[name]; ?> <?php echo '£'. number_format($Item2[Price],2); ?> Add To Cart
<?php echo $Item3[SKU]; ?> <?php echo $Item3[name]; ?> <?php echo '£'. number_format($Item3[Price],2); ?> Add To Cart
[/php]

I am pretty new to PHP however, any help would be GREATLY appriciated.

Thank You

Maybe this will get you going on the right track?
I just like to add you might want to check out : http://php.net/manual/en/function.array-push.php to help you further your progress.
[php]<?php

$data = array(
‘item01’ => array(‘sku’ => 123, ‘name’ => ‘Banana’, ‘price’ => 2.49 ),
‘item02’ => array(‘sku’ => 456, ‘name’ => ‘Apple’, ‘price’ => 3.50 ),
‘item03’ => array(‘sku’ => 789 , ‘name’ => ‘Pear’, ‘price’ => 5.33 )
);

if (isset($_POST[‘action’]) && $_POST[‘action’] == ‘enter’) {

$item = $_POST['item'];

foreach ($data as $key => $value) {
		if ( $item == $key) {
			$sku = $value['sku'];
			$name = $value['name'];
			$price = $value['price'];	
		}
}
$price = number_format($price, 2, '.', '');
    $cart = 'SKU No. ' . $sku . ' Product: ' . $name . ' Price $' . $price;

}

//echo ‘

’;
//print_r($data);
//echo ‘
’;

?>

<?php echo (isset($cart)) ? $cart : 'Shopping Cart'; ?>

Please select your item(s)
<option selected value="item01">Banana</option>
<option value="item02">Apple</option>
<option value="item03">Pear</option>
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service