TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   simple session question (http://www.talkphp.com/absolute-beginners/1840-simple-session-question.html)

Tanax 01-01-2008 08:55 PM

simple session question
 
Hi.

Can I set $_SESSION['something'] to the value of an array?

PHP Code:

$array = array('name' => Tanax'site' => 'TALKPHP');

$_SESSION['admin'] = $array;

echo 
$_SESSION['admin']['name']; 


???

codefreek 01-01-2008 09:16 PM

anyways i dident read your question corectly
now i get what you where asking..
and yes you can set a session to the value of an array.

as tlcandres said

sorry once again :P

TlcAndres 01-01-2008 09:25 PM

yes you can set a session to the value of an array.

Tanax 01-01-2008 10:36 PM

Thanks :)

Wildhoney 01-01-2008 11:24 PM

To the array itself? Your code will work. One question though, why didn't you just run it yourself and see? Just curious.

Village Idiot 01-02-2008 01:36 AM

I could be wrong, but wouldn't assigning the array to the session just be a pointer? You couldn't use it on another page since its stored in the ram which is deleted at the end of th pages execution. I know in C/++ (what php is made in), the root variable for an array is a pointer.

Or on the off chance that that memory address is being used by the time you go the next page it displays that. :-)

Salathe 01-02-2008 01:44 AM

In reply to Village Idiot's post, session variables are serialized (ie, formatted into one long string) before being stored physically (in the file system, database, etc.). Some types of variables can't be stored in sessions -- things that can't be serialized -- such as resources or objects with circular references, but most variable types have no problem being saved as session data.

Village Idiot 01-02-2008 01:45 AM

Ah, I see.


All times are GMT. The time now is 02:45 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0