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
  • 100,477
  • 16
  • 156
  • 200
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
  • 700,868
  • 160
  • 1,392
  • 1,356
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,709
  • 2
  • 29
  • 52