Reputation: 31
I have to do following tasks.
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) 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);
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);
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.
Upvotes: 1
Views: 5906
Reputation: 1419
Try this.
$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.
Upvotes: 1