Foreach在while循环中不工作


Foreach not working in a while loop?

我有一个MySQL数据库,我使用while循环从中获取信息。我还有一个数组,我想用foreach循环,但问题是当我试图在$string中没有数据的情况下嵌套foreach时。$string变量在while循环之外工作,数据库没有任何问题。我需要更改什么才能循环浏览两者?

while ($field = mysql_fetch_assoc($query)) 
{
foreach($string as $strings)
{
//code here
}
}

您的for循环错误。数组应该放在第一位。

  foreach($strings as $string)