Re: Best method to store shopping cart contents

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Bosky, Dave wrote:
Do you have a simple example of how to create a multi-dimensional array and
store it in a session variable?


...

you also asked for a class example, seeing as your asking for this I don't
think your ready for the class example...

$_SESSION['mycart'] = array();
$_SESSION['mycart'][] = array('Product 1', 5.99);
$_SESSION['mycart'][] = array('Product 2', 4.99);
$_SESSION['mycart'][] = array('Product 3', 7.99);

print_r($_SESSION['mycart']);

---
this works due to the superglobal $_SESSION; in order to use the $_SESSION
var (accessable everywhere without the use of global keyword) you must
first call session_start(), which in turn must be called before any output
is sent to the browser.


a quote from the following URL: (read it) http://nl2.php.net/session

"
As of PHP 4.1.0, $_SESSION is available as a global variable just like $_POST, $_GET, $_REQUEST and so on. Unlike $HTTP_SESSION_VARS, $_SESSION is always global. Therefore, you do not need to use the global keyword for $_SESSION. Please note that this documentation has been changed to use $_SESSION everywhere. You can substitute $HTTP_SESSION_VARS for $_SESSION, if you prefer the former. Also note that you must start your session using session_start() before use of $_SESSION becomes available.
"


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux