0

我整日整夜都在做某事,但似乎我没有进一步了解它,因为实际上学习对我来说有点复杂:(

代码是这样的:

    $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并将其保存在一个变量中!我如何做到这一点?我在这里做错了什么?

4

2 回答 2

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);
于 2012-05-04T13:11:01.947 回答
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 条件用于仅用一个空格替换多余的空格。

于 2012-05-04T13:12:55.270 回答