= str_split($word); foreach ($this->candidates as $i => $candidate) { $candidateCharacters = str_split($candidate); for ($j = 0; $j < 5; $j++) { if ($states[$j] === 'absent') { if (in_array($characters[$j], $candidateCharacters, true)) { for ($k = 0; $k < 5; $k++) { if (in_array($states[$k], ['correct', 'present']) && $characters[$k] === $characters[$j]) { continue 2; } } unset($this->candidates[$i]); break; } } elseif ($states[$j] === 'present') { if (!in_array($characters[$j], $candidateCharacters) || $characters[$j] === $candidateCharacters[$j]) { unset($this->candidates[$i]); break; } } else { // 'correct' if ($characters[$j] !== $candidateCharacters[$j]) { unset($this->candidates[$i]); break; } } } } $this->candidates = array_values($this->candidates); }