'Which of these PHP globals might contain user input?', 'options' => [ '$_GET', '$_POST', '$_COOKIE', 'All of the above!' ], 'correct_answer' => 'All of the above!', ], [ 'question' => 'How would I reverse a string in PHP?', 'options' => [ 'reverse()', 'strrev()', 'string_reverse()', "You can't reverse a string in PHP" ], 'correct_answer' => 'strrev()', ], [ 'question' => 'How would I loop through the items in a PHP array?', 'options' => [ 'foreach()', 'each()', 'array_each()', 'for $item of $array' ], 'correct_answer' => 'foreach()', ], ]; /** * Display a single question and it's options: */ function show_question($number, $data){ echo '

' . $data['question'] . '

'; echo ''; } /** * Show the form with the questions: */ function quiz($questions){ ?>

Quiz time!

$question ){ show_question( $number, $question ); } ?>
$question ){ // The correct answer comes from the questions array: $correct_answer = $question['correct_answer']; // Their answer comes from an array that was posted to us: $their_answer = $_POST['answer'][$number]; // If they match, give them a point! if( $their_answer === $correct_answer ){ $score++; } } // What's the best possible score? The number of questions: $max_score = count($questions); ?>

Quiz results

You scored out of !

Have another go?