0
所以我试图输出一个简单的测验的多维数组。我认为这是一个逻辑错误,但我在这个问题上摸不着头脑。问题和答案选择不会显示在浏览器中,但所有的单选按钮都可以。输出多维数组,只显示单选按钮(嵌套的foreach循环)
任何帮助/提示将不胜感激。
<body>
<?php
$q_and_ans = array(
array('question' => 'What\'s the narrators name?',
'ans' => array(
'Greg Scmitz',
'Greg Sanders',
'Greg Smith'),
'correct_ans' => 0),
array('question' => 'What is Greg\'s new friend\'s name?',
'ans' => array(
'Jose',
'Man`enter code here`uel',
'Manuelo'),
'correct_ans' => 1),
array('question' => 'What beer are they drinking?',
'ans' => array(
'Pacifico',
'Corona',
'Pilsener'),
'correct_ans' => 2),
array('question' => 'Where was the Mariscopa video taken?',
'ans' => array(
'Ecuador',
'El Salvador',
'Mexico'),
'correct_ans' => 1),
array('question' => 'What was in the narrator\'s bowl that he failed to mention?',
'ans' => array(
'Shrimp',
'Octopus',
'Squid'),
'correct_ans' => 0),
array('question' => 'What color was Manuel\'s shirt?',
'ans' => array(
'Green',
'White',
'Blue'),
'correct_ans' => 2),
array('question' => 'What was printed on the beer bucket?',
'ans' => array(
'Corona Light',
'Corona Extra',
'Modelo'),
'correct_ans' => 1),
array('question' => 'What kind of vehicle is behind Manuel?',
'ans' => array(
'Car',
'Truck',
'There is no vehicle'),
'correct_ans' => 1),
array('question' => 'What color is the roof over the narrator\s head?',
'ans' => array(
'Brown',
'Tan',
'Green'),
'correct_ans' => 2),
array('question' => 'What kind of animal is on Manuel\s shirt?',
'ans' => array(
'Aligator',
'Duck',
'There is no animal'),
'correct_ans' => 0),
)
?>
我认为这个问题是在嵌套的foreach循环
<form method="post" action="">
<?php
foreach($q_and_ans as $i => $q_and_an):?>
<p><?php $q_and_an['question']?></p>
<?php foreach($q_and_an['ans'] as $a => $ans): ?>
<input type="radio" value="$a" name="question[$i]"> <?php $ans ?>
<?php endforeach;?>
<?php endforeach;?>
<input type="submit" name="submit" id="submit">
</form>
但现在我只能选择一个出口30个收音机的?嗯 – theBartender
<?PHP \t \t \t的foreach($ q_and_ans为$ I => $ q_and_an):?????> \t \t
<?php foreach($ q_and_an ['ans'] as $ a => $ ans):?> ”name =“question []”><?php // $ ANS> \t \t \t\t \t \t
'<形式方法= “POST” 行动= “” > <?PHP的 的foreach($ q_and_ans为$ I => $ q_and_an):>