用字符串加入数组元素

用字符串加入数组元素

问题描述:

我想用字符串连接数组元素(例如:-),我用implode尝试了它,但它在我的代码中不起作用。用字符串加入数组元素

如何解决?

PHP:

<?php 

    $count = 1; 
    $ttttt = json_decode('["110,2"]'); 
    $nnnnn = array("110","1","2"); 
    $fffff = array('name','day','last'); 
    $Rtp = str_replace($nnnnn, $fffff, $ttttt, $count); 
    echo implode(" - ", $Rtp); // This output is as: name,last 

?> 

DEMO:http://codepad.viper-7.com/ZNiBWy

+0

如果你改变你的'json'字符串,将工作:'json_decode( '[ “110”, “2”]') ;' – 2013-02-18 15:34:30

+0

这正是你编程要做的。你期望的答案是什么? – Husman 2013-02-18 15:36:09

你JSON是无效的,你期待的方式,它产生只有一个值110,2

更改为["110","2"],你的内爆应该没问题。

你有一个数组$ ttttt = array(110,2)。 然后使用str_replace替换此数组中的所有值,如下所示110 - > name,2 - > last和1 - > day。

所以(110,2)成为( “名”, “最后”)