'What colour is the sky?', 'c' => array('Red', 'Green', 'Blue', 'Black'), 'a' => '3'), array('t' => 'Why am I here?', 'c' => array('Because', 'Why not?', 'Good question'), 'a' => '1')); shuffle($_SESSION['questions']); $_SESSION['next'] = 0; } function getNextQuestion() { $next = $_SESSION['next']; if($next >= count($_SESSION['questions'])) { return false; } $q = $_SESSION['questions'][$next]; echo json_encode(array('score' => $_SESSION['score'], 'number' => $next, 'question' => $q)); $_SESSION['next'] = $next + 1; return true; } function scoreAnswer($q, $a) { if($_SESSION['questions'][$q]['a'] == $a) { $_SESSION['score']++; } } function finish() { echo json_encode(array('score' => $_SESSION['score'])); session_destroy(); } ?>