[英]PHP - Array not looping through foreach
$array = Array(1,2,3);
foreach ($array as $identifier => $values_arr);
{
echo(123);
}
The result is 123 instead of 123123123. 结果是123而不是123123123。
What you have are actually two different segments of code. 实际上,您拥有的是两个不同的代码段。
The first: 首先:
foreach ($array as $identifier => $values_arr);
doesn't actually do anything, and is stopped. 实际上不执行任何操作,并且已停止。
And the second: 第二个:
{echo (123);}
so the output is 123
所以输出是
123
to get into the foreach you will need to remove the semi-colon: 要进入foreach,您需要删除分号:
foreach ($array as $identifier => $values_arr){
echo(123);
}
There is an extra colon on the end of the foreach line. 在foreach行的末尾有一个多余的冒号。 The same issue often happens with if/else lines.
if / else行经常发生相同的问题。 I am posting this as I could not find the answer via Google search.
我发布此消息是因为我无法通过Google搜索找到答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.