如何从Codeigniter的会话中的数组中获取数据? [英] How to get data from an array inside session in codeigniter?

查看:54
本文介绍了如何从Codeigniter的会话中的数组中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从会话内部的数组中获取数据.我想获取每个数组的名称.但是当我像下面的代码一样打印$ x和$ y时,它什么也没打印

i want to get data from an array inside of session. i want to get the name of each array. But when i print $x and $y like in the code below, it doesn't print anything

正确之前的答案,但是关于此的

THE ANSWER BEFORE IS CORRECT BUT HOW ABOUT THIS

$this->session->userdata['namearray'];

这是会话的print_r

this is print_r of the session

Array (
        [0] => stdClass Object
        (

                     [name] =>a

          )

         [1] => stdClass Object
        (

                     [name] =>b


             )

    )

foreach ($this->session->userdata['namearray'] as $x=>$y){
    print_r("this is x".$x);
    print_r("this is y".$y);
}

推荐答案

我已经为您的查询编写了可能的解决方案,并在必要时提及了注释.看看是否对您有帮助.

I've written a possible solution for your query, comments are mentioned wherever necessary. See if it helps you.

$nameArray = $this->session->userdata('namearray'); // access the session data like this (remove namearray with your session name)

foreach ($nameArray as $x){ // traverse the data
   echo "this is x ".$x->name;  // use -> to access objects
}

这篇关于如何从Codeigniter的会话中的数组中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆