Last active
August 29, 2015 14:02
-
-
Save colinrotherham/9090d5328b8f4b886fc4 to your computer and use it in GitHub Desktop.
PHP to JSON output for “Who Wants to Be a Millionaire?”
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Question list | |
----------------------------------- */ | |
$questions = array | |
( | |
(object) array | |
( | |
'question' => 'Complete this phrase. As sick as a...', | |
'answers' => array('Penguin', 'Parrot', 'Puffin', 'Partridge'), | |
'answer' => 'Parrot', | |
'value' => 0 | |
), | |
(object) array | |
( | |
'question' => 'Which legal document states a person’s wishes regarding the disposal of their property after death?', | |
'answers' => array('Will', 'Shall', 'Would', 'Should'), | |
'answer' => 'Will', | |
'value' => 100 | |
), | |
(object) array | |
( | |
'question' => 'Complete the title of the James Bond film The Man With The Golden...', | |
'answers' => array('Gun', 'Tooth', 'Delicious', 'Eagle'), | |
'answer' => 'Gun', | |
'value' => 200 | |
), | |
(object) array | |
( | |
'question' => 'Which of these fruits shares its name with something superior or desirable?', | |
'answers' => array('Apricot', 'Mango', 'Grapefruit', 'Plum'), | |
'answer' => 'Plum', | |
'value' => 300 | |
), | |
(object) array | |
( | |
'question' => 'In which sport do two teams pull at the opposite ends of a rope?', | |
'answers' => array('Ice hockey', 'Basketball', 'Tug of war', 'Polo'), | |
'answer' => 'Tug of war', | |
'value' => 500 | |
), | |
(object) array | |
( | |
'question' => 'Where would a cowboy wear his chaps?', | |
'answers' => array('On his hands', 'On his arms', 'On his legs', 'On his head'), | |
'answer' => 'On his legs', | |
'value' => 1000 | |
), | |
(object) array | |
( | |
'question' => 'Which of these zodiac signs is not represented by an animal that grows horns?', | |
'answers' => array('Taurus', 'Capricorn', 'Aquarius', 'Aries'), | |
'answer' => 'Aquarius', | |
'value' => 2000 | |
), | |
(object) array | |
( | |
'question' => 'Sherpas and Gurkhas are native to which country?', | |
'answers' => array('Russia', 'Ecuador', 'Nepal', 'Morocco'), | |
'answer' => 'Nepal', | |
'value' => 4000 | |
), | |
(object) array | |
( | |
'question' => 'Prime Minister Tony Blair was born in which country?', | |
'answers' => array('England', 'Northern Ireland', 'Scotland', 'Wales'), | |
'answer' => 'Scotland', | |
'value' => 8000 | |
), | |
(object) array | |
( | |
'question' => 'Whose autobiography has the title, “A Long Walk to Freedom”?', | |
'answers' => array('Ranulph Fiennes', 'Mother Teresa', 'Nelson Mandela', 'Mikhail Gorbachev'), | |
'answer' => 'Nelson Mandela', | |
'value' => 16000 | |
), | |
(object) array | |
( | |
'question' => 'Duffel coats are named after a town in which country?', | |
'answers' => array('Belgium', 'Holland', 'Germany', 'Austria'), | |
'answer' => 'Belgium', | |
'value' => 32000 | |
), | |
(object) array | |
( | |
'question' => 'Complete this stage instruction in Shakespeare’s ‘The Winter’s Tale’, ‘Exit, pursued by a...’?', | |
'answers' => array('Tiger', 'Clown', 'Bear', 'Dog'), | |
'answer' => 'Bear', | |
'value' => 64000 | |
), | |
(object) array | |
( | |
'question' => 'The young of which creature is known as a ‘squab’?', | |
'answers' => array('Salmon', 'Horse', 'Pigeon', 'Octopus'), | |
'answer' => 'Pigeon', | |
'value' => 125000 | |
), | |
(object) array | |
( | |
'question' => 'Who is the patron saint of Spain?', | |
'answers' => array('Saint James', 'Saint John', 'Saint Benedict', 'Saint Peter'), | |
'answer' => 'Saint John', | |
'value' => 150000 | |
), | |
(object) array | |
( | |
'question' => 'Which king was married to Eleanor of Aquitaine?', | |
'answers' => array('Henry I', 'Henry II', 'Richard I', 'Henry V'), | |
'answer' => 'Henry II', | |
'value' => 1000000 | |
) | |
); | |
/* | |
Output as JSON | |
----------------------------------- */ | |
// Tell browser this is JSON | |
header('Content-type: application/json; charset=utf-8'); | |
// More options for PHP 5.4 | |
$options = version_compare(phpversion(), '5.4', '<')? | |
null : JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES; | |
echo json_encode($questions, $options); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment