CodeIgniter Forums
Question: SESSION and ARRAY - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Question: SESSION and ARRAY (/showthread.php?tid=2338)



Question: SESSION and ARRAY - El Forum - 07-30-2007

[eluser]Unknown[/eluser]
Hello all,

i have a questen to SESSION and ARRAY with CI. I should like to use array in session. Here example use without CI.

Code:
$_SESSION['name'][$_POST['title']] = array($_POST['description'], $_POST['number_of'], $_POST['place']);

This work good Smile.

The example with CI.

Code:
$Name['Name'][$this->input->post('title')] = array($this->input->post('description'), $this->input->post('number_of'), $this->input->post('place'));
$this->session->set_userdata($Name);

This doesn´t work.
I am overwride the old content.


Question: SESSION and ARRAY - El Forum - 07-30-2007

[eluser]Michael Wales[/eluser]
No testing involved, just off the top of head.
Code:
$sess_data = array(
  $this->input->post('title') => array(
    'description'=>$this->input->post('description'),
    'number_of'=>$this->input->post('number_of'),
    'place'=>$this->input->post('place')));
$this->session->set_userdata($sess_data);

Theoretically, when you retrieved this session variable it would be an array (although you'll need to know what the title is):
Code:
list($description, $number_of, $place) = $this->session->userdata('this_is_the_title');



Question: SESSION and ARRAY - El Forum - 07-31-2007

[eluser]Unknown[/eluser]
thanks for the fast answer. I don´t mean it.

here the array with the normal session

Array ( [Donut] => Array ( [0] => I like it [1] => 5 [2] => 1 ) [Football] => Array ( [0] => i like it realy [1] => 1 [2] => 2 ) [Notebook] => Array ( [0] => 3 GHz 160 GB [1] => 1 [2] => 3 ) )

i want speak one variable and this is inside the one variable.
i want give this with foreach back.....

here is the example without CI

Code:
foreach ($_SESSION['Name'] as $key => $index){
    echo $key.'<br />';
    foreach ($index as $value){
     echo $value.'<br />';
   }
}