2 d sessions

use of 2 dimensional array in sessions

Page 1 of 1

2 Replies - 804 Views - Last Post: 18 November 2008 - 07:16 AM Rate Topic: -----

#1 garg.hitesh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-November 08

2 d sessions

Posted 18 November 2008 - 06:09 AM

can any body help me to use 2 dimensional array in sessions for php?
Is This A Good Question/Topic? 0
  • +

Replies To: 2 d sessions

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3030
  • Posts: 10,567
  • Joined: 08-August 08

Re: 2 d sessions

Posted 18 November 2008 - 06:18 AM

It's no different than any other variable:
if(isset($_SESSION['TwoD']))
{
$two_d_array= $_SESSION['TwoD'];
}
.
.
.

$_SESSION['TwoD'] = $two_d_array;


Was This Post Helpful? 0
  • +
  • -

#3 pemcconnell  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 54
  • View blog
  • Posts: 472
  • Joined: 05-August 08

Re: 2 d sessions

Posted 18 November 2008 - 07:16 AM

Here is a quick example:
<?php
session_start();
session_destroy(); // will stop the sessions appending data on page refresh - testing purposes

$ar[] = 'a';
$ar[] = 'b';
$ar[] = 'c';

$_SESSION['my_array'] = $ar;

unset($ar); // remove the array $ar

echo 'flat (2D) array: <br />';
print_r($_SESSION['my_array']);

$_SESSION['my_multi_array'][] = $_SESSION['my_array'];

$ar[] = 'd';
$ar[] = 'e';
$ar[] = 'f';

$_SESSION['my_array_2'] = $ar;

unset($ar); // remove the array $ar

$_SESSION['my_multi_array'][] = $_SESSION['my_array_2'];


echo '<br />multidimensional (3D) array: <br />';
print_r($_SESSION['my_multi_array']);
?>


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1