Guest User

Untitled

a guest
May 20th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. declare(strict_types = 1);
  3.  
  4. class WordBoolean {
  5. private $word = null;
  6. private $firstRow = ["q","w","e","r","t","y","u","i","o","p"]; //first row of the keyboard
  7. private $secondRow = ["a","s","d","f","g","h","j","k","l"]; //second row
  8. private $thirdRow = ["z","x","c","v","b","n","m"]; //third row
  9. private $counter1 = null;
  10. private $counter2 = null;
  11. private $counter3 = null;
  12. private $bool = false;
  13.  
  14. public function wordCheck(string $word) { //checks if the word is written only by keys from one row
  15. $word = str_split($word ,1);
  16. for ($i = 0; $i < count($word); $i++) {
  17. if (in_array($word[$i], $this->firstRow)) {
  18. $this->counter1 += 1;
  19. } elseif (in_array($word[$i], $this->secondRow)) {
  20. $this->counter2 += 1;
  21. } elseif (in_array($word[$i], $this->thirdRow)) {
  22. $this->counter3 += 1;
  23. }
  24. }
  25. if ($this->counter1 == count($word)) {
  26. $this->bool = true;
  27. return $this->bool;
  28. } elseif ($this->counter2 == count($word)) {
  29. $this->bool = true;
  30. return $this->bool;
  31. } elseif ($this->counter3 == count($word)) {
  32. $this->bool = true;
  33. return $this->bool;
  34. }
  35. return $this->bool;
  36. }
  37. }
  38. $obj = new WordBoolean();
  39. echo $obj->wordCheck('qwemsad'); //the input
  40. ?>
Add Comment
Please, Sign In to add comment