PHP数组问题?

时间:2009-12-08 06:43:16

标签: php

当数组在回显时显示其内容时,尝试停止重复单词has been entered

这是代码。

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

6 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

呃,echo $array[$x];

答案 2 :(得分:0)

...

怎么样

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

答案 3 :(得分:0)

更新后的评论:

您可以使用类似

的内容
foreach ($array as $a) {
  echo $a;
}

echo "has been entered";

答案 4 :(得分:0)

至于我能得到你的问题;尝试以下代码:

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

答案 5 :(得分:0)

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

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