1、將字符串轉(zhuǎn)換成數(shù)組的幾個(gè)函數(shù): (1)explode(separate,string) 示例:$str = "Hello world It's a beautiful day"; explode(" ",$str);//以空格為分界點(diǎn) 返回:array([0]=>"Hello",[1]=>"world",[2]=>"It's",[3]=>"a",[4]=>"beautiful",[5]=>"day") (2)str_split(string,length) //length指每個(gè)數(shù)組元素的長度,默認(rèn)情況下為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) 反序列化,將已序列化的字符串返回到原數(shù)組形式。 2、將數(shù)組轉(zhuǎn)換成字符串的幾個(gè)函數(shù): (1)implode(separate,array)? //explode的反向操作,separate默認(rèn)為空字符 示例:$array = ('hello','world','!'); implode(" ",$array); 返回:"hello world !" (2)serialize(array) 序列化,將數(shù)組按照固定格式轉(zhuǎn)換成字符串;
發(fā)表評(píng)論