Jump to content

serialize function


siri

Recommended Posts

Can anyone explain what exactly the serialize function does in the following code snippet:if (isset($_SESSION[products])) { 12: print "<b>Your cart:</b><ol>\n"; 13: foreach (unserialize($_SESSION[products]) as $p) { 14: print "<li>$p";

Link to comment
Share on other sites

Oh...big edit!I understood what you meant now.Well...if someone orders something, some script will create a session and like...if she/he has a session it'll show what he/she has ordered I guess.It's kinda like loginscripts that uses sessions. Well...not really, but yeah, maybe you get it :)And please tell me if that was explained bad, cause I'm really (O_o - I almost said a bad word <=) bad at explaining things.

Link to comment
Share on other sites

What I can figure out from the manual unserialize and Serializing objects) it turns a string into an object.And serialize turns an object into a string. This let you store an object (as string) in for example cookies or sessions (as those normally ony can store strings/numbers).Hope that helped!Good Luck and Don't Panic!btw: you can't/shouldn't use "constants":

if (isset($_SESSION[products])) {

to get a value from arrays/hashes, use strings:

if (isset($_SESSION['products'])) {

...

Link to comment
Share on other sites

What I can figure out from the manual unserialize and Serializing objects) it turns a string into an object.And serialize turns an object into a string. This let you store an object (as string) in for example cookies or sessions (as those normally ony can store strings/numbers).
A little more percisely, when you have an object that you would like to store in a cookie or in a file so that a user can shut down the application and return to it another time and reload the object from storage, you would have to "serialize" it into a string. Once an object is serialized, it can easily be saved as a string and converted back to an object ("deserialize" or "unserialize") and used in the application.EDIT: Here's a link that explains it even better: http://en.wikipedia.org/wiki/Serialization
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...