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.
Result of php executing
Full code of words_guess.php
- <?php
- $words = [
- "BOT",
- "COT",
- "DOT",
- "GOT",
- "HOT",
- "JOT",
- "LOT",
- "MOT",
- "NOT",
- "OAT",
- "OFT",
- "OOT",
- "OPT",
- "ORT",
- "OUT",
- "POT",
- "ROT",
- "SOT",
- "TAO",
- "THO",
- "TOD",
- "TOE",
- "TOG",
- "TOM",
- "TON",
- "TOO",
- "TOP",
- "TOR",
- "TOT",
- "TOW",
- "TOY",
- "TWO",
- "WOT"
- ];
- $excl_pos = [
- // 1 => "",
- // 2 => "",
- // 3 => "",
- // 4 => "",
- // 5 => "",
- // 6 => "",
- // 7 => "",
- // 8 => "",
- // 9 => "",
- ];
- //$excl_let = [ "D", "P", "M", "N"];
- $excl_let = "DPMNLW";
- foreach ($words as $k=>$word) {
- foreach ($excl_pos as $lpos=>$letter) {
- $pos = (strpos($word, $letter, $lpos-1))+1;
- if ($pos === $lpos){
- unset($words[$k]);
- }
- }
- /*foreach ($excl_let as $letter) {
- $pos = (strpos($word, $letter));
- if ($pos !== false){
- unset($words[$k]);
- }
- }*/
- if (strpbrk($word, $excl_let)){
- unset($words[$k]);
- }
- }
- var_dump($words);