Welcome Guest, Not a member yet? Register   Sign In
defining two dimentional session array
#1

[eluser]ratna[/eluser]
i want to define session like this.

$dataArray=array(
'one'=>'this is one',
'two'=>array('abc','this is abc')
);

i can get the value of 'one' index but not of 'two' index.
is there any way out for defining session array like this?
please help. it's urgent.
#2

[eluser]Zorancho[/eluser]
If you put the array in the session data like that, then you can fetch them like this:
Code:
$sess_data = array(
    'one' => 'this is one',
    'two' => array('abc', 'this is abc')
);
$this->session->set_userdata($sess_data);
echo '<pre>';
//Print the session userdata
print_r($this->session->all_userdata());
echo '</pre>;
This gives:
Array(
[one] => this is one
[two] => Array
(
[0] => abc
[1] => this is abc
)

);

Which means one is string and two is array... so you can get them individually like this:
Code:
//Fetch each from the session userdata
$one = $this->session->userdata('one');
$two = $this->session->userdata('two');

//This is how you access their values
echo $one .'<br/>';
echo $two[0] .'<br/>';
echo $two[1];
This prints:

this is one
abc
this is abc

You can also make for and foreach loops through the two array and get the values as well.
Hope this helps
#3

[eluser]ratna[/eluser]
it worked. thank you very much for your help.
#4

[eluser]überfuzz[/eluser]
If you're tinkering with php-code, this is handy:

Code:
echo "<pre>";
print_r($what);  //this gives a simple output of $what
echo "</pre>";

Edit, oh I just saw that you've got it already. Confusedmirk:




Theme © iAndrew 2016 - Forum software by © MyBB