问题
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