访问数组$ this-> session->数组

时间:2011-02-10 02:42:42

标签: php arrays

如何访问像$this->session->userdata('auth')这样的数组?

print_r()显示:

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

但我不能使用$this->session->userdata('auth')[ncli] ...

2 个答案:

答案 0 :(得分:1)

将它放在变量中:

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

您无法()[]的原因是PHP just doesn't support it yet

答案 1 :(得分:1)

您将能够从PHP 5.4中引入阵列解除引用。然后使用辅助变量。

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