How to create a Session Array() variable in PHP

0
1259

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.

[php]

session_start();

[/php]

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

// It represent a container of data.
$_SESSION[‘cointainer’] = array();

[/php]
Lastly is storing data in the session variable that you have declared.
[php]

$_SESSION[‘cointainer’][0][‘Firstname’]=”Janobe”;

$_SESSION[‘cointainer’][0][‘Lastname’]=”Palacios”;

$_SESSION[‘cointainer’][1][‘Address’]=”Kabankalan City”;

$_SESSION[‘cointainer’][1][‘Email’]=”[email protected]”;

// and you can also do this one.

$_SESSION[’employee’] = array(“Firstname”=>”Janobe”, “Lastname”=>”Palacios”, “Address”=>”Kabankalan”, “Email”=>”[email protected]”);

[/php]
Output :
[php]

//It presents the value and their curresponding keys.
echo print_r($_SESSION[‘cointainer’]) .’
;

echo print_r($_SESSION[’employee’]);

[/php]

Looking for more source code? Type your keyword here here!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.