Php Sessions

Hi

How do you store several items in the same session variable.

I’m trying to figure out how to create a shopping cart so I want to allow the user to select a product and add it to the session named ‘Cart’.

Then if the user selects another product how can it be added to the same variable.

Just to see how sessions work, ive tried the following

$_SESSION[‘cart’]=apple
$_SESSION[‘cart’]=orange

When trying to echo them out only the second one is displayed.

Lewis

$_SESSION[‘cart’]=apple
$_SESSION[‘cart’]=orange

||

$_SESSION[‘cart’] = array(‘apple’,‘orange’);

<?php
session_start();

$_SESSION['cart'] = array();

$cart =& $_SESSION['cart'];

array_push($cart, 'foo');
array_push($cart, 'bar');
array_push($cart, 'wing');
array_push($cart, 'wang');

print_r($cart);

/*
    Array
    (
        [0] => foo
        [1] => bar
        [2] => wing
        [3] => wang
    )
*/