ITSourceCode.com

We Exist to Provide 100% 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";
  2.  
  3. $_SESSION['cointainer'][0]['Lastname']="Palacios";
  4.  
  5. $_SESSION['cointainer'][1]['Address']="Kabankalan City";
  6.  
  7. $_SESSION['cointainer'][1]['Email']="jannopalacios@gmail.com";
  8.  
  9.  
  10. // and you can also do this one.
  11.  
  12.   $_SESSION['employee'] = array("Firstname"=>"Janobe", "Lastname"=>"Palacios", "Address"=>"Kabankalan", "Email"=>"jannopalacios@gmail.com");

Output :

  1. //It presents the value and their curresponding keys.
  2. echo print_r($_SESSION['cointainer']) .'<br />;
  3.  
  4. echo print_r($_SESSION['employee']);
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

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