Re: Best method to store shopping cart contents
| From: | Jochem Maas | Date: | Fri, 28 Jan 2005 18:41:08 +0000 |
| Subject: | Re: Best method to store shopping cart contents | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-207617@lists.php.net to get a copy of this message | ||
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. "