PHP: Incremental list using SESSION? -


i'm working on simple shopping cart, i'm able output single form result (post), have no idea how incrementaly add lines newer items when user comes form , adds items (they being overriden).

here's currenly have:

       <?php  session_start();  //getting list $list[]= $_session['list'];   $_session['list'] = array( 'item' => $item,  'quantity' => $quantity, 'price' => $price);  //list echo  "<b>shopping cart</b></br>";   echo "1. ".$_session['list']['item']." ".$_session['list']['quantity']." units".", ".$_session['list']['price']." usd.";  //returning list $_session['list'] = $list;   ?> 

a sample of current output is:

    shopping cart 1. banana 3 units, 2 usd. 

the ideal output should this:

    shopping list 1. banana 3 units, 2 usd. 2. coffe 4 units, 6 usd. 3. etc , infinte... 

let multi-dimensional array:

//add element list $_session['list'][] = array(   'item' => $item,    'quantity' => $quantity,   'price' => $price), ); 

then use foreach loop on it:

foreach($_session['list'] $key => $item) {   echo $key, '. ', $item['item'], ' ', $item['quantity'], ' units'; } 

Comments