How to create a Session Array() variable in PHP

0
99

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
(Visited 135 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here