zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    linux系统中批量对一类文件重命名
    hdu4751 Divide Groups
    tyvj1614 魔塔魔塔!
    noip2012 疫情控制
    黄学长模拟day1 大逃亡
    黄学长模拟day1 球的序列
    黄学长模拟day1 某种密码
    约瑟夫问题及其变形
    秦皇岛 I 题
    暴力搜索 + 剪枝
  • 原文地址:https://www.cnblogs.com/jianqingwang/p/6145090.html
Copyright © 2011-2022 走看看