How to get data from an array inside session in codeigniter?

只愿长相守 提交于 2020-06-17 12:56:30

问题


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'];

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);
}

回答1:


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
}


来源:https://stackoverflow.com/questions/61888505/how-to-get-data-from-an-array-inside-session-in-codeigniter

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!