0

How can i access an array like this $this->session->userdata('auth') ?

print_r() displays:

Array (
  [ncli] => 0
  [nomecli] => somename 
  [nomcli1] => Administrador 
  [morcli] => company 
  [nuser] => admin 
  [pwdcli] => pwdadmin 
) 

But I can't use $this->session->userdata('auth')[ncli]...

Brad Christie
  • 98,427
  • 16
  • 148
  • 198
noinstance
  • 761
  • 1
  • 7
  • 23

2 Answers2

1

Put it in a variable:

$data = $this->session->userdata('auth');
echo $data['ncli'];

The reason why you can't do ()[] is that PHP just doesn't support it yet.

Community
  • 1
  • 1
BoltClock
  • 665,005
  • 155
  • 1,345
  • 1,328
1

You will be able to do so from PHP 5.4 where they've introduced array dereferencing. Till then use an auxiliary variable.

$auth = $this->session->userdata('auth');
$auth['ncli'];
mhitza
  • 5,569
  • 2
  • 27
  • 51