数组Foreach循环仅打印最后一个项目 [英] Array Foreach Loop Prints Last Item Only
本文介绍了数组Foreach循环仅打印最后一个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下为什么只打印一个水果?
Why does the following only print one fruit?
$fruits = array('banana','apple','orange');
foreach($fruits as $fruit);
{
echo $fruit."<br>";
}
输出:
orange
推荐答案
因为您在 foreach
行的末尾有一个多余的分号。删除它,一切都会好起来。
Because you have an extra semicolon at the end of the foreach
line. Remove it, and all should be well.
这篇关于数组Foreach循环仅打印最后一个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文