2016-10-31 46 views
0

请告诉我如何在PHP中显示for循环中的数组? 我有这个数组:在循环中显示数组

while($q = mysqli_fetch_assoc($selectQuestResult)) {  
    $answers[] = array(array($q['name']),array(round($total,1)));} 

那么我想它显示:

+0

请检查每个回路或同时净 – madankundu

+0

sorru循环,但我必须使用 –

+0

向我们展示你已经尝试了什么。 – Epodax

回答

0
for($i = 0; $i < count($answers); $i++) 
{ 
    echo($answers[$i][0][0].':'.$answers[$i][1][0]."<br />\n"); 
} 
+0

虽然此代码片段可能会解决问题,但它并不能解释为什么或如何回答问题。请[请为您的代码添加解释](// meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers),因为这确实有助于提高帖子的质量。请记住,您将来会为读者回答问题,而这些人可能不知道您的代码建议的原因。 **举报人/评论者:** [仅限代码解答,例如downvote,请勿删除!](// meta.stackoverflow.com/a/260413/2747593) –

0

我必须用一个for循环使得这听起来像愚蠢的大学教授的技巧。但是,没关系。 for循环可以在其中包含break语句。而且,他们不必在for语句中包含最终条件。

for($i = 0; ; $i++) { 
    $q = mysqli_fetch_assoc($selectQuestResult); 
    if (!$q) break; 
    $answers[] = array($q['name'], round($total, 1)); 
} 
for ($i = 0; $i < count($answers), $i++) { 
     /* do something with $answers[i] */ 
}