如何将数组转换为逗号分隔的string?

可能重复:
如何在PHP中创build逗号分隔列表中的数组?

我的数组看起来像这样:

Array ( [0] => lorem [1] => ipsum [2] => dolor [3] => sit [4] => amet ) 

如何将其转换为像这样的string与PHP?

 $string = 'lorem, ipsum, dolor, sit, amet'; 
 $arr = array ( 0 => "lorem", 1 => "ipsum", 2 => "dolor"); $str = implode (", ", $arr); 

直接从文档 :

 $comma_separated = implode(",", $array); 

让你的数组变成一个variables并使用implode。

 $array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); echo $comma_separated; // lastname,email,phone 

http://php.net/manual/en/function.implode.php

你正在寻找implode()

$string = implode(",", $array);