用字符串连接数组元素


Join array elements with a string

我想要用字符串(例如:-)连接数组元素,我尝试过使用内爆,但它在我的代码中不起作用。

如何修复?

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
?>

演示:http://codepad.viper-7.com/ZNiBWy

您的JSON并不像您期望的那样有效,它只生成一个值110,2

将其更改为["110","2"],您的内爆应该可以。

您有一个数组$ttttt=数组(110,2)。然后,使用str_replace将该数组中的所有值替换为110->name、2->last和1->day。

因此(110,2)变为("name","last")