Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // task 1
- $data[] = array(
- 'task' => "Lorem Ipsum",
- 'clue' => "Find them in Fiona's blog",
- 'answer' => "Lorem Ipsum"
- );
- // task 2
- $data[] = array(
- 'task' => "Lorem Ipsum",
- 'clue' => "Find them in Fiona's blog",
- 'answer' => "Lorem Ipsum"
- );
- // initialize flags
- $i = 0;
- $isCorrect = false;
- $answered = false;
- // process submitted <form>
- if (isset($_POST) AND $_POST)
- {
- foreach ($_POST as $key => $answer)
- {
- if (preg_match('/task([0-9]+)/i', $key, $matches))
- {
- $i = $matches[1];
- // check answer
- if ($data[$i]['answer'] == strtolower(trim($answer)))
- {
- $i += 1;
- $isCorrect = true;
- }
- $answered = true;
- }
- }
- }
- echo $isCorrect ? '{"result": true}' : '';
Add Comment
Please, Sign In to add comment