douyin8809 2015-02-05 15:27
浏览 40
已采纳

如何将2个字符串与分隔符连接在一起? [关闭]

I have a string like this $value[0] = "8000297c - 1360598144 "

I explode them into 2 pieces by doing this : $elements = explode('-', $value[0]);

Then I created 2 variables to store them :

$first = strtolower($elements[0]); // 8000297c 
$last  = strtoupper($elements[1]); // 1360598144

Now- after formatting them, I want to join them back to the original format like this

  • $first."-".$last

I was thinking to use implode() function, and I tried

  • $polish_sku = implode("-", $first, $last); - then, I got this :

enter image description here

I hope someone don't mind and point out what I did wrong. :D

  • 写回答

5条回答 默认 最新

  • duanliaouu965826 2015-02-05 15:29
    关注

    if you want to use implode

    implode("-", array($first, $last));
    

    or just concat them ?

    $first . "-" . $last
    

    or use printf/sprintf ?

    printf("%s-%s", $first, $last)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛