PHP的serialize()函数有什么作用? [英] What is PHP's serialize() function for?

查看:382
本文介绍了PHP的serialize()函数有什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚了解了serialize()unserialize()函数.有什么用?我知道人们将事物序列化到数据库中.您能给我一些有用的示例用法吗?

我还看到了javascript中的序列化代码,这是一样的吗?可以使用php unserialize()取消序列化javascript中的字符串吗?

解决方案

PHP序列化允许您将数组或对象保留为文本形式.将数组分配给$ _SESSION之类的东西时,它允许PHP将其存储在文本文件中,然后在以后重新创建它.序列化用于对象和变量. (只需确保已事先声明了对象使用的类)

另一方面,Wordpress通过将序列化的数组直接存储在数据库中,将其用于非常相似的方法.如果保留键=>值的数据库,由于数组的灵活性,这可能会非常有益,您可以在value参数中存储任何内容.

这里是链接(由第一位评论者提供): http://us3.php.net/serialize

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()?

解决方案

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

这篇关于PHP的serialize()函数有什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆