Home  >  Article  >  Backend Development  >  php数组跟字符串的相互转换,数据结构不变

php数组跟字符串的相互转换,数据结构不变

WBOY
WBOYOriginal
2016-06-13 13:11:42771browse

php数组和字符串的相互转换,数据结构不变

一个描述 PHP 数据的函数。返回值是一个字符串。有的时候为了把一些数据转为字符串存起来,但是希望保持数据原来有结构和内容。就要用到这个函数。

$a=array('data'=>"hi", 123);
$b=serialize($a);//对数组进行序列化
echo $b;? //这个就是描述过的数组但在这里是一个字符串而已

$c=unserialize($b); //把描述过的数据恢复(反序列化)
print_r($c);?? //还原成为 $a ,数组结构并没有丢失。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn