在codeigniter届阵列更新 [英] Session Array Update in codeigniter

查看:134
本文介绍了在codeigniter届阵列更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须做以下工作。

1)以一个数组,并将其保存到SEESION。在启动它是空的错误,我这样做

1) Take an array and save it into the seesion. At start it is empty error and i am doing this

    $id_array=array();
    $this->session->set_userdata('PID', $id_array);

2),之后我把一些来自用户的价值,然后去到控制器..Take数组从session.which最初是空的。我插入用户价值为数组,然后再插入数组会话。
我这样做像这样...

2) After that i take some value from the user and then go to the controller ..Take an array from the session.which was initially empty .I insert that user value into array and then again insert that array into session. i am doing it like this...

 $username['name']=$this->session->userdata['PID'];
 array_push($username,$PID);//this $PID is variable which i m getting from user
 $this->session->set_userdata('PID', $username);

所以用户重复此过程,二,三的时间。因此多数民众赞成意味着3值已插入到会话不同index.But最后当我从会话和打印it..These值是有,但该指数相同的数据。但根据我的reuqirement指数应不同的充。我是打印它像

So user repeat this process two and three time. SO thats mean 3 value has been inserted into session into different index.But when at last i take data from session and print it..These values are there but the index is same...But according to my reuqirement index should be differnt.i am print it like that

 $username['name']= $this->session->userdata('PID');
 print_r($username);

我已经在三个time.6进入6应该出现三个时间在0 1 2索引,但6出现3次,但像这样相同的索引。

I have entered 6 in three time.6 should be appear three time on 0 1 2 index but 6 appear 3 time but on the same index like this.

Array ( [name] => Array ( [name] => Array ( [name] => Array ( [name] => Array ( [name] => Array ( ) [0] => 6 ) [0] => 6 ) [0] => 6 ) [0] => 6 ) )

我不知道是什么问题。

I dont know what is the problem.

推荐答案

试试这个。

 $username=$this->session->userdata['PID'];  // read the session
 array_push($username,$PID);//this $PID is variable which i m getting from user
 $this->session->set_userdata('PID', $username);                               

This will remove the 'name' index from array.

这篇关于在codeigniter届阵列更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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