我整天都在做一些事情,但似乎我没有进一步研究它,因为实际上我学习它有点复杂:(
代码是这样的:
$aDoor = $_POST['zeilenid'];
if(empty($aDoor))
{
echo("You didn't select anything.");
}
else
{
$N = count($aDoor);
echo("You selected $N entry ID(s): ");
for($i=0; $i < $N; $i++)
{
$str = $aDoor[$i];
$str = ereg_replace(" ",",",$str);
echo($str . " ");
}
}
它不起作用 - 我想要ID,这将显示不以这种方式显示它们:8 9 10 而是这样:8,9,10 并将其保存在一个变量中!我怎么做到这一点?我在这里做错了什么?
答案 0 :(得分:0)
试试:
$aDoor = $_POST['zeilenid'];
if(empty($aDoor))
{
echo("You didn't select anything.");
}
else
{
$N = count($aDoor);
echo("You selected $N entry ID(s): ");
echo join(", ", $aDoor);
}
join将数组的所有元素组合成一个字符串,并在每个元素之间插入第一个参数
编辑:保存:
$str = join(", ", $aDoor);
答案 1 :(得分:0)
$clean_search = str_replace(' ', ',', $user_search);
$search_words = explode(' ', $clean_search);
$final_search_words = array();
if (count($search_words) > 0) {
$final_search_words[] = $user_search;
foreach ($search_words as $word) {
if (!empty($word)) {
$final_search_words[] = $word;
}
}
}
此代码将用逗号替换空格,if条件用于替换仅有一个空格的额外空格。