topo - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of topo.php

  1. <?php
  2. $topo = [
  3.     'Japan' => 'Tokyo',
  4.     'UK' => 'London',
  5.     'Egypt' => 'Cairo',
  6.     'Mexico' =>  'Mexico stad',
  7.     'USA'  => 'Washington D.C.',
  8.     'India' => 'New Delhi',
  9.     'Zuid-Korea' => 'Seoul',
  10.     'China' => 'Peking',
  11.     'Nigeria' => 'Abuja',
  12.     'Argentina' => 'Buenos Aires',
  13. ];
  14. $result = [];
  15. foreach ($topo as $country => $city) {
  16.     echo "Wat is de hoofdstad van $country?" . PHP_EOL;
  17.     $input = readline('-> ');
  18. }
  19.  
  20. if ($input != ($city)) {
  21.     echo "Helaas, $input is niet de hoofdstad van $country" . PHP_EOL;
  22.     echo "Het correcte anwoord is $city" . PHP_EOL;
  23. } else {
  24.     ($result[$country] == $input);
  25.     echo "Correct" . PHP_EOL;
  26. }
  27.  
  28. $good = '0';
  29. foreach ($topo as $country => $city) {
  30.     if ($city == $result[$country]) {
  31.         $good++;
  32.     }
  33.     echo "je hebt $good van de 10 goed" . PHP_EOL;
  34. }
  35.  
  36.  
File Description
  • topo
  • PHP Code
  • 22 Sep-2021
  • 831 Bytes
You can Share it: