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


一个数组要入库,发现不可以,特定用函数转为字符串入库

$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);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM