= 1000000) break; //If there's an even digit (or a 5) we can instantly exclude it as when rotated it will not not be a prime. if ( strpos((string) $data[1], "0") !== false || strpos((string) $data[1], "2") !== false || strpos((string) $data[1], "4") !== false || strpos((string) $data[1], "5") !== false || strpos((string) $data[1], "6") !== false || strpos((string) $data[1], "8") !== false ) { continue; } $primes[] = (int) $data[1]; } fclose($handle); } echo "File read\n"; $count = 1+1; //2 and 5 are primes but not included foreach($primes as $prime) { //echo "Now testing $prime\n"; $newprime = $prime; for($rotate = 1; $rotate < strlen($prime); $rotate++) { $newprime = substr($newprime, -1, 1).substr($newprime, 0, -1); //echo "New prime: $newprime\n"; if(!in_array($newprime, $primes)) { continue 2; } } $count++; echo $prime.PHP_EOL; } echo "Total: $count\n";