php 在 codeigniter 的会话数组中回显/打印变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14434401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Echo/print variables in a session array of codeigniter
提问by itsover9000
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!
提前致谢!
回答by Muhammad Raheel
Use this
用这个
$session_data = $this->session->all_userdata();
echo '<pre>';
print_r($session_data);
回答by diggersworld
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'];
回答by Deepu
It will be an array so you cant display the contents using echo. use print_r()for displaying the array.
它将是一个数组,因此您无法使用echo. 使用print_r()用于显示阵列。
回答by user3475414
Suppose you are taking data from a text box named "username", then you can print the session variable data in the following way :
假设您正在从名为“用户名”的文本框中获取数据,那么您可以通过以下方式打印会话变量数据:
$uname=$this->input->post('username'); //uname is the variable storing the user input.
$this->session->set_userdata('uname',$uname); //setting session variable assigning name as "uname".
echo $this->session->userdata('uname'); // echoing session data

