Registering an Array Variable with a Session : Session Variables « Cookie Session « PHP

Registering an Array Variable with a Session


if ( empty( $_SESSION['products'] ) ) {

if ( is_array( $_REQUEST['form_products'] ) ) {
  $_SESSION['products'] = array_unique(
    array_merge( $_SESSION['products'],
          $_REQUEST['form_products'] )
<title>Registering an Array Element with a Session</title>
<form action="<?php print $_SERVER['PHP_SELF']?>" method="post">
<select name="form_products[]" multiple="multiple" size="3">
<input type="submit" value="choose" />
<a href="index.php">A content page</a>

Related examples in the same category

1.A session variable can be destroyed with a call to session_unregister().
2.Accessing Session Variables
3.Adding Session Data
4.Checking Session Data
5.Reading Session Data
6.Registering Variables with a Session
7.Storing Complex Data Types in Sessions
8.Storing Complex Data Types to session
9.Storing Simple Data Types in Sessions