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.

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

Lastly is storing data in the session variable that you have declared.



$_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]”);

Output :

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

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


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


Please enter your comment!
Please enter your name here

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