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
You can find prime numbers and non prime numbers from 1 to your limit and its count.
public function prime_checker($count){
$counter=0;
$no_prime=0;
for($i=2 ; $i<=$count; $i++ ){
for($j=2 ; $j<$i ; $j++ ){
if($i % $j == 0){
echo $i.'is not prime
';
$no_prime=$i;
break;
}
}
if($i != $no_prime){
$prime_numbers[$counter]=$i;
$counter=$counter+1;
}
}
echo '
'.$counter.'prime numbers
';
for($i=0 ; $i<$counter ; $i++ ){
echo $prime_numbers[$i].' is prime
';
}
}