`
moqiang02
  • 浏览: 523913 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

php数组与字符串转换

 
阅读更多
1、将字符串转换成数组的几个函数:
(1)explode(separate,string)
示例:$str = "Hello world It's a beautiful day";
explode(" ",$str);//以空格为分界点
返回:array([0]=>"Hello",[1]=>"world",[2]=>"It's",[3]=>"a",[4]=>"beautiful",[5]=>"day")
(2)str_split(string,length) //length指每个数组元素的长度,默认情况下为1
示例:$str = "hello";
$a=str_split($str,3);
$b=str_split($str);
返回:a([0]=>"hel",[1]=>"lo") b([0]=>"h",[1]=>"e",[2]=>"l",[3]=>"l",[4]=>"o")
(3)unserialize(string)
反序列化,将已序列化的字符串返回到原数组形式。

2、将数组转换成字符串的几个函数:
(1)implode(separate,array) //explode的反向操作,separate默认为空字符
示例:$array = ('hello','world','!');
implode(" ",$array);
返回:"hello world !"
(2)serialize(array)
序列化,将数组按照固定格式转换成字符串;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics