What is PHP's serialize() function for?

前端 未结 4 1704
孤街浪徒
孤街浪徒 2020-12-08 19:29

I just learned about the serialize() andunserialize() functions. What are some uses for this? I know people serialize things to put into a databas

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 20:07

    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

提交回复
热议问题