Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP数组问题?_Php - Fatal编程技术网

PHP数组问题?

PHP数组问题?,php,Php,当数组在回显时显示其内容时,试图阻止输入的单词重复 这是代码 echo "$array[$x] has been entered"; 呃,echo$array[$x]? 怎么样 echo $array[$x]." has been entered"; 更新后的评论: 你可以用像 foreach ($array as $a) { echo $a; } echo "has been entered"; 据我所知,你的问题;请尝试以下代码: foreach($array as $key =

当数组在回显时显示其内容时,试图阻止输入的单词
重复

这是代码

echo "$array[$x] has been entered";

呃,
echo$array[$x]

怎么样

echo $array[$x]." has been entered";

更新后的评论:

你可以用像

foreach ($array as $a) {
  echo $a;
}

echo "has been entered";

据我所知,你的问题;请尝试以下代码:

foreach($array as $key => $value)
{
  // if this is the first item
  if ($key === 1)
  {
    echo "$array[$key] has been entered";
  }
  else
  {
    echo $array[$key];
  }
}

使用单引号而不是双引号:

echo implode(', ', $array) . ' has been entered';

你的问题显然没有提供足够的背景。您提供的代码只打印一次…请澄清您想要的内容。我希望显示所有数组值,但我希望输入的单词只显示一次。我希望这有帮助?
echo implode(', ', $array) . ' has been entered';