doulv8162 2013-12-04 22:10
浏览 90
已采纳

PHP - 不通过foreach循环的数组

$array = Array(1,2,3);
foreach ($array as $identifier => $values_arr);
{
     echo(123);
}

The result is 123 instead of 123123123.

  • 写回答

2条回答 默认 最新

  • dongqu5650 2013-12-04 22:17
    关注

    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

    to get into the foreach you will need to remove the semi-colon:

    foreach ($array as $identifier => $values_arr){
         echo(123);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?