Welcome Guest, Not a member yet? Register   Sign In
Easiest way to acces an array with session->userdata
#1

[eluser]Unknown[/eluser]
Hi Guys,

One of the problems I encounter is retrieving a value of an array within a session. I will give you an example:

<?php
/* SET SOME DATA */
$arr_person = array('firstname' => 'Danny', 'lastname' => Klaassen', 'initials' => 'D');
$arr_login = array('username' => 'dklaassen', 'rank' => 1);

$arr_data = array('person' => $arr_person, 'login' => $arr_login);

$this->session->set_userdata($arr_data);
?>

What if I want to check the users rank. Now I use the following code:

<?php
/* Check user rank bitwise */
$arr_user = $this->session->userdata('login');

if ($arr_user['rank'] & 1)
{
...
}
else
{
...
}
?>

I prefer to access the rank immediately, without the intervention of $arr_user. Is there any way to achieve that?
#2

[eluser]Enéas Gesing[/eluser]
Yes,

Just do:

$this->session->userdata['login']['rank'];
#3

[eluser]Unknown[/eluser]
Damn... so easy... Thnkz for helping me out




Theme © iAndrew 2016 - Forum software by © MyBB