开发者

PHP array question?

开发者 https://www.devze.com 2022-12-13 07:40 出处:网络
Try开发者_如何学运维ing to stop the words has been entered from repeating when the array displays its contents when echoed.

Try开发者_如何学运维ing to stop the words has been entered from repeating when the array displays its contents when echoed.

Here is the code.

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


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


uh, echo $array[$x];?


??

how about

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


As far as i could get your question; try below code:

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


After your updated comment:

You can use something like

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

echo "has been entered";


Use single-quotes rather than double-quotes:

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

精彩评论

暂无评论...
验证码 换一张
取 消