我无法找到一个好的(比foreach更好)的方法来做到这一点:
$arr = ['blue', 'red', 'green', 'brown', 'yellow'];
$glue = ["\t","\t","\n",'-'];
echo mergeImplode($glue, $arr); // blue\tred\tgreen\nbrown-yellow
答案 0 :(得分:0)
有多种方法可以做到这一点。我喜欢array_reduce
,这就是我使用它的原因:)
$arr = ['blue', 'red', 'green', 'brown', 'yellow'];
$glue = ["\t","\t","\n",'-'];
array_reduce ( $arr, function($carry, $item) use (&$glue){
$gl = array_pop($glue);
return ($gl ? $gl : '') . $item . $carry;
}, '' ] )