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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.