words_guess - 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 words_guess.php

  1. <?php
  2.  
  3. $words = [
  4.     "BOT",
  5.     "COT",
  6.     "DOT",
  7.     "GOT",
  8.     "HOT",
  9.     "JOT",
  10.     "LOT",
  11.     "MOT",
  12.     "NOT",
  13.     "OAT",
  14.     "OFT",
  15.     "OOT",
  16.     "OPT",
  17.     "ORT",
  18.     "OUT",
  19.     "POT",
  20.     "ROT",
  21.     "SOT",
  22.     "TAO",
  23.     "THO",
  24.     "TOD",
  25.     "TOE",
  26.     "TOG",
  27.     "TOM",
  28.     "TON",
  29.     "TOO",
  30.     "TOP",
  31.     "TOR",
  32.     "TOT",
  33.     "TOW",
  34.     "TOY",
  35.     "TWO",
  36.     "WOT"
  37. ];
  38. $excl_pos = [ 
  39.    // 1 => "",
  40.   //  2 => "", 
  41.   //  3 => "",
  42.   //  4 => "",
  43.   //  5 => "",
  44.   //  6 => "",
  45.   //  7 => "",
  46.   //  8 => "",
  47.   //  9 => "",
  48. ];
  49. //$excl_let = [ "D", "P", "M", "N"];
  50. $excl_let = "DPMNLW";
  51. foreach ($words as $k=>$word) {
  52.     foreach ($excl_pos as $lpos=>$letter) {
  53.         $pos = (strpos($word, $letter, $lpos-1))+1;
  54.         if ($pos === $lpos){
  55.             unset($words[$k]);
  56.         }
  57.     }
  58.     /*foreach ($excl_let as $letter) {
  59.         $pos = (strpos($word, $letter));
  60.         if ($pos !== false){
  61.             unset($words[$k]);
  62.         }
  63.     }*/
  64.     if (strpbrk($word, $excl_let)){
  65.         unset($words[$k]);
  66.     }
  67.     
  68. }
  69.  
  70.  
  71. var_dump($words);
  72.  
File Description
  • words_guess
  • PHP Code
  • 19 May-2024
  • 1.03 Kb
You can Share it: