How to Retrieve Data from Session Array Variable in PHP

0
28

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"=>"jannopalacios@gmail.com");

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 />';
  4.  
  5. }

Output :

Firstname :Janobe
Lastname :Palacios
Address :Kabankalan
Email :jannopalacios@gmail.com

Facebook Comments
(Visited 54 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here