Jump to content

Session Variable Array


barkster

Recommended Posts

How do I put a array into a session variable?? I have a text field that is stored in as a comman seperated values and I need to dump it into a session and then acess the session like print $_SESSION['Names'][0] I tried this but it doesn't work.

$_SESSION['Names'] = array(split(",",$_POST['names']));

I was trying to access at $_SESSION['Names'][0] but I get "array"
Link to comment
https://forums.phpfreaks.com/topic/20176-session-variable-array/
Share on other sites

[quote author=kenrbnsn link=topic=107412.msg430979#msg430979 date=1157758672]
To jefkin:
You don't need to serialize any data that is put into a session variable, since all data is automagically serialized when the session array is stored.

Ken
[/quote]

Izat so!  ;D

learn something new every day!

Thanks Ken.
Link to comment
https://forums.phpfreaks.com/topic/20176-session-variable-array/#findComment-88760
Share on other sites

Cool, wondered how you actually saw that, here is what I got so I assume I have to access it as multidimensional array$_SESSION['Names'][0][0]??  Why is it an array of arrays?

Array
(
    [0] => Array
        (
            [0] => 10
            [1] => John
        )

)

Thanks for all the suggestions, I'll try a the explode option also.
Link to comment
https://forums.phpfreaks.com/topic/20176-session-variable-array/#findComment-88805
Share on other sites

[quote author=barkster link=topic=107412.msg431032#msg431032 date=1157766675]
Why is it an array of arrays?

[/quote]

Beacause your code "=array(split()) " makes it so.

split() (or explode which is slightly more efficient in this case) returns the array you need. You are then placing this array into the first element of an array by placing array(..) round it.
Link to comment
https://forums.phpfreaks.com/topic/20176-session-variable-array/#findComment-88890
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.