How to Retrieve Data from Session Array Variable in PHP


session array variable
In this tutorial, I will teach you how to retrieve data from a session array variable in php. Retrieving data from session array is just very easy to do. With the use of Foreach Loop, every data that you have stored in a session variable will appear in order.

Let’s begin :

First, start a session for reading the session handler.

Second,declare a session array variable and store any value in it.

  1. //It represents the employee basic information.
  2.  $_SESSION['employee'] = array("Firstname"=>"Janobe", "Lastname"=>"Palacios", "Address"=>"Kabankalan", "Email"=>"[email protected]");

Third, fetch the data from a session array variable using foreach loop.

  1. foreach ($_SESSION['employee'] as $key =>  $value) {
  2.     # code...
  3. echo $key .' :'.$value .'<br />';
  5. }

Output :

Firstname :Janobe
Lastname :Palacios
Address :Kabankalan
Email :[email protected]

Facebook Comments


Please enter your comment!
Please enter your name here