Free Source Code and Tutorials

Custom Search

How to create a Session Array() variable in PHP

session array variable
Today, I will teach you how to create a session array in Hypertext Preprocessor (PHP). Session Array() variable has the ability to hold multiple data at once. This will help you store various data that can be accessed in different pages.


Let’s begin:


First, you have to start the session to read all the session variable that are being declared.

Second, declare a SESSION ARRAY variable to be able to store multiple data.

  1. // It represent a container of data.
  2. $_SESSION['cointainer'] = array();

Lastly is storing data in the session variable that you have declared.

  1. $_SESSION['cointainer'][0]['Firstname']="Janobe";
  3. $_SESSION['cointainer'][0]['Lastname']="Palacios";
  5. $_SESSION['cointainer'][1]['Address']="Kabankalan City";
  7. $_SESSION['cointainer'][1]['Email']="";
  10. // and you can also do this one.
  12.   $_SESSION['employee'] = array("Firstname"=>"Janobe", "Lastname"=>"Palacios", "Address"=>"Kabankalan", "Email"=>"");

Output :

  1. //It presents the value and their curresponding keys.
  2. echo print_r($_SESSION['cointainer']) .'<br />;
  4. echo print_r($_SESSION['employee']);
Facebook Comments
(Visited 7 times, 1 visits today)
Share this

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked * © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!

%d bloggers like this: