在PHP循环中建立逗号分隔的字符串 [英] Build comma separated string in PHP Loop
本文介绍了在PHP循环中建立逗号分隔的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你们好,我需要这样做,
Hello Guys i need to do this,
我有一个普通循环
foreach ($stuffs as $stuff) {
echo $stuff;
}
让我们假设$ stuff是我拥有的mysql表的'id',我不想在下一个结果中显示,所以我想构建一个像这样的字符串
Lets assume $stuff is an 'id' of a mysql table what i have and i dont want to be showed in next results, so i want to build a string like this
1,23,54,67 (comma separated)
因此该字符串将在mysql查询中排除已显示的结果. 我该怎么办?
So that string will be in mysql query to exclude results that already have been shown. how can i do that?
应该内爆吗?我该如何实现?
Should be with implode? How can i achieve that?
推荐答案
内置应该是这样的工具:>
implode should be the tool:
implode(",", $stuffs);
将返回一个用逗号分隔的列表.
will return a comma separated list.
$myarray=array(1,2,"hello",4,5);
echo implode(",", $myarray);
返回
1,2,hello,4,5
这篇关于在PHP循环中建立逗号分隔的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文