Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- declare(strict_types = 1);
- class WordBoolean {
- private $word = null;
- private $firstRow = ["q","w","e","r","t","y","u","i","o","p"]; //first row of the keyboard
- private $secondRow = ["a","s","d","f","g","h","j","k","l"]; //second row
- private $thirdRow = ["z","x","c","v","b","n","m"]; //third row
- private $counter1 = null;
- private $counter2 = null;
- private $counter3 = null;
- private $bool = false;
- public function wordCheck(string $word) { //checks if the word is written only by keys from one row
- $word = str_split($word ,1);
- for ($i = 0; $i < count($word); $i++) {
- if (in_array($word[$i], $this->firstRow)) {
- $this->counter1 += 1;
- } elseif (in_array($word[$i], $this->secondRow)) {
- $this->counter2 += 1;
- } elseif (in_array($word[$i], $this->thirdRow)) {
- $this->counter3 += 1;
- }
- }
- if ($this->counter1 == count($word)) {
- $this->bool = true;
- return $this->bool;
- } elseif ($this->counter2 == count($word)) {
- $this->bool = true;
- return $this->bool;
- } elseif ($this->counter3 == count($word)) {
- $this->bool = true;
- return $this->bool;
- }
- return $this->bool;
- }
- }
- $obj = new WordBoolean();
- echo $obj->wordCheck('qwemsad'); //the input
- ?>
Add Comment
Please, Sign In to add comment