Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

serialization - What is PHP's serialize() function for?

I just learned about the serialize() andunserialize() functions. What are some uses for this? I know people serialize things to put into a database. Could you give me some example uses where it is helpful?

I also see serialized code in javascript, is this the same? Can a serialized string in javascript can be unserialized with php unserialize()?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

PHP serialize allows you to keep an array or object in a text form. When assigning arrays to things like $_SESSION, it allows PHP to store it in a text file, and then recreate it later. Serialize is used like this for objects and variables. (Just make sure you have declared the class the object uses beforehand)

Wordpress on the other hand uses it for a very similar method, by storing the serialized arrays directly in a database. If you keep a database of keys => values, this could be very beneficial because of the flexibility of arrays, you can store anything in the value parameter.

And heres the link (courtesy of first commentor): http://us3.php.net/serialize


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...