Why does this $_SESSION code not work as intended?
Posted: Wed Feb 09, 2011 12:11 pm
Hey,
I am new to PHP and new to DevNetwork. I am learning PHP and cannot figure out why this is the case.
Suppose you have a session:
I am looking at an ecommerce example from Munach book and it is coded:
which is translated to be session_as_array[key] = someNumber
but then I start playing around and change it to this:
To me, as a beginner this code is easier to understand. After I made the change, I believe it still adds the item to the cart but other parts of the code does not work which leads me to believe that the two are not completely equal. Can someone explain to me why?
Thanks!!!!
I am new to PHP and new to DevNetwork. I am learning PHP and cannot figure out why this is the case.
Suppose you have a session:
Code: Select all
$_SESSION['cart'] = array();Code: Select all
$_SESSION['cart'][$product_id] = round($quantity, 0);but then I start playing around and change it to this:
Code: Select all
$temp_session = $_SESSION['cart'];
$temp_session[$product_id] = round($quantity,0);Thanks!!!!