Skip to content

Instantly share code, notes, and snippets.

@snowfluke
Created August 8, 2023 17:41
Show Gist options
  • Save snowfluke/c4808c4fd1659aeaa564230d7cc7a515 to your computer and use it in GitHub Desktop.
Save snowfluke/c4808c4fd1659aeaa564230d7cc7a515 to your computer and use it in GitHub Desktop.
<?php
$questions = array(
array(
'question' => 'Soal 1',
'prompt' => 'gitar : ... ≈ ... : pukul',
'options' => array(
'A' => 'bernyanyi tukang',
'B' => 'kayu besi',
'C' => 'petik jimbe',
'D' => 'musik paku',
'E' => 'senar gendang'
)
),
array(
'question' => 'Soal 2',
'prompt' => 'hard disk : ... ≈ ... : uang',
'options' => array(
'A' => 'piringan logam',
'B' => 'data dompet',
'C' => 'piringan kertas',
'D' => 'disket barter',
'E' => 'komputer penghasilan'
)
)
);
foreach ($questions as $index => $question) {
$questionNumber = $index + 1;
$questionId = 'question' . $questionNumber;
echo '<div class="question' . ($index === 0 ? ' active' : '') . '" id="' . $questionId . '">';
echo '<h5>' . $question['question'] . '</h5>';
echo '<p>' . $question['prompt'] . '</p>';
echo '<div class="options">';
foreach ($question['options'] as $optionValue => $optionText) {
$dataCorrect = ($optionValue === 'B') ? ' data-correct' : '';
echo '<label>';
echo '<input type="radio" name="answer' . $questionNumber . '" value="' . $optionValue . '"' . $dataCorrect . '> ' . $optionText;
echo '</label>';
}
echo '</div>';
echo '</div>';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment