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 46 47 48 49 50 51 52 53 54 55 56
| <?php
/****************************************************/
$qcm = array('1'=>array(
'libelle'=>'je vois grace à ','img'=>null,
'choix'=>array(
'mes yeux.'=>true,
'ma tete.'=>false,
'mon nez.'=>false)),
'2'=>array(
'libelle'=>'je sens grace à . ','img'=>Null,
'choix'=>array(
'mon bras.'=>false,
'mon nez.'=>true,
'mon coude.'=>false)),
'3'=>array(
'libelle'=>'high kick dans la gueule grace à','img'=>Null,
'choix'=>array(
'mon pied.'=>true,
'mon genoux.'=>false,
'mon orteil.'=>false)));
/**************************************************/
echo "<form action='test.php' method='post'>";
// $num= '1','2','3'.
//$question='libelle','img','choix'.
foreach($qcm as $num=>$question){
echo '<h3>'.'QUESTION '.$num.'</h3>'.$qcm[$num]['img'].'<br />'.' -'.$qcm[$num]['libelle'].' :<br />';
//$reponse='mes yeux','ma tete','mon nez' (pour la question 1)
//$choix='true','false','false'
foreach($question['choix'] as $reponse=>$choix){
echo '<input type="checkbox" name="reponse_box['.$num.'][]" value="'.$reponse.'">'.$reponse.'<br />';
}
echo '<p />';
}
echo'<input type="RESET" value="Effacer" />';
echo'<input type="SUBMIT" name="btn_valid" value="Valider" />';
echo'</form>';
/*************************************************************/
if(isset($_POST['reponse_box'])){
print_r ($_POST['reponse_box']);
foreach ($qcm as $num => $question){
echo'<p />QUESTION '.$num.' - '.$qcm[$num]['libelle'].' : <br />';
echo '--->vous avez repondu : ';
foreach($question['choix'] as $reponse=>$choix){
if(isset($_POST['reponse_box'][$num])) {
echo $reponse;
if ($qcm[$num]['choix'][$reponse][$choix] == true) {//if ($qcm[$num]['choix'][$reponse] == TRUE) {
echo'<br />bonne réponse';
}
else {
echo'<br />mauvaise réponse';
}
}break;
}
}
}
?> |
Partager