如何使用JSON以外的方法将数组转换为字符串? [英] How to convert array to a string using methods other than JSON?

查看:112
本文介绍了如何使用JSON以外的方法将数组转换为字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了使用JSON之外,PHP中用于将数组转换为字符串的函数是什么?

What is a function in PHP used to convert array to string, other than using JSON?

我知道有一个直接类似于JSON的函数.我只是不记得了.

I know there is a function that directly does like JSON. I just don't remember.

推荐答案

serialize() 是您的功能正在找.它将以特定于PHP的内部格式返回其输入数组或对象的字符串表示形式.可以使用unserialize()将字符串转换回其原始形式.

serialize() is the function you are looking for. It will return a string representation of its input array or object in a PHP-specific internal format. The string may be converted back to its original form with unserialize().

但是请注意,并非所有对象都可以序列化,或者某些对象可能仅是部分可序列化的并且无法使用unserialize()完全还原.

But beware, that not all objects are serializable, or some may be only partially serializable and unable to be completely restored with unserialize().

$array = array(1,2,3,'foo');
echo serialize($array);

// Prints
a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;s:3:"foo";}

这篇关于如何使用JSON以外的方法将数组转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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