1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| <?php
$qcm = array(
array(
'q' => "L'oeuf ou la poule",
'choix' => array('Poule', 'Oeuf', 'Les 2'),
'rep' => 0
),
array(
'q' => 'Einstein vs Newton',
'choix' => array('Einstein', 'Newton'),
'rep' => 1
),
array (
'q' => 'Meilleur album du Revival',
'choix' => array('Bayou Country', "Cosmo's Factory", 'Pendulum', 'Green River'),
'rep' => 3
)
);
if (isset($_POST['submit'])) {
for ($i = 0; $i < count($qcm); ++$i) {
if (isset($_POST["q$i"])) {
echo "Q$i: "
.(($_POST["q$i"] == $qcm[$i]['rep']) ? 'bonne' : 'mauvaise')
." réponse<br/>\n";
}
}
} else {
?>
<form method="post" action="qcm.php">
<?php
for ($i = 0; $i < count($qcm); ++$i) {
echo "<br/>{$qcm[$i]['q']}<br/>\n";
for ($k = 0; $k < count($qcm[$i]['choix']); ++$k) {
echo "<input type='radio' name='q$i' value='$k'/>{$qcm[$i]['choix'][$k]}<br/>\n";
}
}
?>
<input type="submit" name="submit" value="Valider"/>
</form>
<?php
}
?> |
Partager