Guest User

Untitled

a guest
Feb 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. // task 1
  4.  
  5. $data[] = array(
  6.     'task'   => "Lorem Ipsum",
  7.     'clue'   => "Find them in Fiona's blog",
  8.     'answer' => "Lorem Ipsum"
  9. );
  10.  
  11. // task 2
  12.  
  13. $data[] = array(
  14.     'task'   => "Lorem Ipsum",
  15.     'clue'   => "Find them in Fiona's blog",
  16.     'answer' => "Lorem Ipsum"
  17. );
  18.  
  19. // initialize flags
  20.  
  21. $i = 0;
  22. $isCorrect = false;
  23. $answered = false;
  24.  
  25. // process submitted <form>
  26.  
  27. if (isset($_POST) AND $_POST)
  28. {
  29.     foreach ($_POST as $key => $answer)
  30.     {
  31.         if (preg_match('/task([0-9]+)/i', $key, $matches))
  32.         {
  33.             $i = $matches[1];
  34.            
  35.             // check answer
  36.            
  37.             if ($data[$i]['answer'] == strtolower(trim($answer)))
  38.             {
  39.                 $i += 1;
  40.                 $isCorrect = true;
  41.  
  42.             }
  43.            
  44.             $answered = true;
  45.         }
  46.     }
  47. }
  48.  
  49. echo $isCorrect ? '{"result": true}' : '';
Add Comment
Please, Sign In to add comment