您的位置:首页 > 编程语言 > PHP开发

PHP工作笔记:数组转字符串与字符串转数组

2016-12-08 15:22 246 查看
一个数组要入库,发现不可以,特定用函数转为字符串入库

$data = array(
'http://img4.bitautoimg.com/autoalbum/files/20110420/734/22494073435215_1565563_15.jpg',
'http://img4.bitautoimg.com/autoalbum/files/20110420/718/22494071876770_1565547_15.jpg',
'http://img2.bitautoimg.com/autoalbum/files/20110420/671/22494067187672_1565545_15.jpg'
);


用“,”分割,并转为字符串

$data = array(
'http://img4.bitautoimg.com/autoalbum/files/20110420/734/22494073435215_1565563_15.jpg',
'http://img4.bitautoimg.com/autoalbum/files/20110420/718/22494071876770_1565547_15.jpg',
'http://img2.bitautoimg.com/autoalbum/files/20110420/671/22494067187672_1565545_15.jpg'
);
$data = implode(",",$data);


转换后的data效果:

http://img4.bitautoimg.com/autoalbum/files/20110420/734/22494073435215_1565563_15.jpg,http://img4.bitautoimg.com/autoalbum/files/20110420/718/22494071876770_1565547_15.jpg,http://img2.bitautoimg.com/autoalbum/files/20110420/671/22494067187672_1565545_15.jpg


  把字符串按照分隔符切割出来使用:

$newdata = explode(",",$data);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: