Welcome Guest, Not a member yet? Register   Sign In
Two dimensional session array
#1

[eluser]Unknown[/eluser]
Hi guys!

I got some problem with creating a two dimensional session array in Codeigniter. I used the following code before I was using codeigniter and it worked perfectly:
Code:
$_SESSION['products'][] = array(
                             ...
            );

The previous code allways adds the new information after the last one in the array. The code i use in Codeigniter replace existing data with new.

I use the following code in Codeigniter:
Code:
$session_array[] = array(
                     ...
        );
                
$this->session->set_userdata('products', $session_array);

How can I create a two dimensional session array without replacing existing data with new data?

Thanks in advance!
// Henrik Gerdin
#2

[eluser]WanWizard[/eluser]
This is not supported by the Session library.

Get the entire array, update something, put the entire array back. Or extend the session class, and add a method to it directly accesses the session storage.
#3

[eluser]Irfan Cikoglu[/eluser]
This is not supported. You can use json_encode or serialize for session storing and json_decode or unserialize for decode.
#4

[eluser]WanWizard[/eluser]
That's even more complicated than just pull the entire array out to get to a single key.
#5

[eluser]Irfan Cikoglu[/eluser]
[quote author="WanWizard" date="1310082036"]That's even more complicated than just pull the entire array out to get to a single key.[/quote]
Yes Smile




Theme © iAndrew 2016 - Forum software by © MyBB