Echo/print variables in a session array of codeigniter
36,217
Solution 1
If you set data like this:
$this->session->set_userdata('newdata', $newdata);
You will need to access it like this:
$this->session->userdata('newdata');
So you could do:
// dump all content
var_dump($this->session->userdata('newdata'));
// or access array indexes like so.
$post_array = $this->session->userdata('newdata');
echo $post_array['index'];
Solution 2
Use this
$session_data = $this->session->all_userdata();
echo '<pre>';
print_r($session_data);
Solution 3
It will be an array so you cant display the contents using echo
. use print_r()
for displaying the array.
Related videos on Youtube
Author by
itsover9000
Updated on July 11, 2020Comments
-
itsover9000 almost 4 years
I'm trying to write a code where I use this particular line of code to store my post values in a session array
$this->session->set_userdata('newdata', $newdata);
The problem is, I can not seem to echo out the values inside it.
This is how I echo them out:
<?php echo $this->session->userdata('suffix'); ?>
Is there another way to echo out sessions?
Thanks in advance!
-
Peon over 11 yearsHe is trying to echo not the whole session, but only a specific element, which, most likely, will be a string, but who knows.
-
Admin over 6 yearshow to display it in view page that session value