如何使PHP会话变量深入嵌套在数组中?

如何使PHP会话变量深入嵌套在数组中?,php,Php,已经尝试了许多排列,以从PHP会话中获取值。会话是一个对象数组,我认为它有键值对。这是每个循环的键/值输出的结构 Array ( [laboratory_roster] => Array ( [employee_entrance] => stdClass Object ( [step] => employee_entrance

已经尝试了许多排列,以从PHP会话中获取值。会话是一个对象数组,我认为它有键值对。这是每个循环的键/值输出的结构

Array
(
    [laboratory_roster] => Array
        (
            [employee_entrance] => stdClass Object
                (
                    [step] => employee_entrance
                    [employee_first_name] => asdfasd
                    [employee_last_name] => fasdfasdfv
                    [employee_access_code] => valid
                    [employee_email] => blah@blah.com
                    [employee_state_origin] => NY
                    [employee_kit_for_whom] => employee_kit_for_employee
                )

        )

)
这是我编写的foreach循环,用于显示上面的输出:

   foreach($_SESSION['laboratory_roster']['employee_entrance'] as $key=>$value)
    {
        // and print out the values
        echo 'The value of $_SESSION['."'".$key."'".'] is '."'".$value."'".' <br />';
    }
而这个

$first_name = $_SESSION['employee_entrance'][1];
$first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'];
 $first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'][0];
而这个

$first_name = $_SESSION['employee_entrance'][1];
$first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'];
 $first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'][0];
而这个

$first_name = $_SESSION['employee_entrance'][1];
$first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'];
 $first_name = $_SESSION['laboratory_roster']['employee_entrance']['employee_first_name'][0];
什么都不管用!如何将最里面的值放入PHP变量可能很简单,但我没有得到它。谢谢你的帮助

试试看:

$first_name = $_SESSION['laboratory_roster']['employee_entrance']->employee_first_name;
作为雇员,入口是一个对象(stdClass的实例)而不是数组。

两种方式:
1转换为stdClass:
$stdClass=json\u解码(json\u编码($\u会话))然后使用
[]
访问

2转换为数组:
$array=json\u decode(json\u encode($\u SESSION),true)
然后使用
->

访问也尝试了这一点:$first\u name=$\u SESSION['laboratory\u花名册]['employee\u entry']->employee\u first\u name@根据发布的示例,它必须工作。请看@Oliver,但不是这样。如果我这样做。。我没有得到任何渲染:$first\u name=$\u SESSION['[laboratory\u花名册]['employee\u entrance']->employee\u first\u name;echo('first name'.$first\u name);一定有东西被缓存了/有问题。正在工作。谢谢!另一方面。