I’m looking at this function: serialize() for PHP and I don’t really understand what is it’s function. Can someone provide a simple example with output?
I’m looking at this function: serialize() for PHP and I don’t really understand what
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Basically, the goal of
serializeis to transform any (alsmost) kind of data to a string, so it can be transmitted, stored, …A quick example :
Will get you this output :
And, later, you can
unserializethat string, to get the original data back :Will get you :
Common uses include :
Note, though, that using
serializeis great when you are only working with PHP (as it’s a PHP-specific format, that’s able to work with almost any kind of PHP data, and is really fast) ; but it’s not that great when you have to also work with something else than PHP (as it’s PHP-specific). In those cases, you can use XML, JSON (seejson_encodeandjson_decode), …In the PHP manual, you can also read the Object Serialization section, btw.