I\'m trying to create a function which checks whether the number is prime or not. BUT I want this function to echo to the user \'prime\' or \'NOT prime\' - and that\'s where my
I made a similar one where a user types in a number and PHP checks if the number is prime or not.
HTML
See if your number is a prime number
PHP
if ($_GET) {
$i = 2;
$isPrime = true;
while ($i < $_GET['number']) {
if ($_GET['number'] % $i == 0){
// Number is NOT prime
$isPrime = false;
}
$i++;
}
if ($isPrime){
echo ''.$i.' is a prime number!';
} else {
echo '
'.$i.' is NOT a prime number';
}
}
Hopefully this works for you.