可能的复制品: 如何在 PHP 中从数组中创建逗号分隔的列表
我的数组是这样的:
Array ( [0] => lorem [1] => ipsum [2] => dolor [3] => sit [4] => amet )
如何用 php 将它转换成这样的字符串?
$string = 'lorem, ipsum, dolor, sit, amet';
你在找 implode()
implode()
$string = implode(",", $array);
使数组成为一个变量并使用内爆。
$array = array('lastname', 'email', 'phone'); $comma_separated = implode(",", $array); echo $comma_separated; // lastname,email,phone
Http://php.net/manual/en/function.implode.php
直接来自 医生:
$comma_separated = implode(",", $array);
$arr = array ( 0 => "lorem", 1 => "ipsum", 2 => "dolor"); $str = implode (", ", $arr);