【发布时间】:2011-01-07 15:46:19
【问题描述】:
我几乎总是使用这种方法从数组中获取“Word1, Word2, Word3”('Word1', 'Word2', 'Word3')
这是最短或可接受的方法吗?有更好的解决方案吗?
$sentence = '';
foreach ($words as $word) {
$sentence .= $word . ", ";
}
$final_sentence = substr($sentence, 0, -2);
echo $final_sentence; //outputs contents of $words array separated by ,
【问题讨论】:
-
这 3 个答案在时间上有多接近真的很可怕,即使一个答案最初确实包含错字(此后已修复)。
-
大声笑,您已经为此重建
implode()+1 -
哇!,这太棒了!.. 我很尴尬我一直在忽视
implode()!