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

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

问题描述

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

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天全站免登陆