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