In this article, you will learn How to Create Prime and Non-Prime Number in PHP.

<?php
//tells the no is prime/non-prime
$num=23;
for($j=1;$j<=$num;$j++){
    for($k=2;$k<$j;$k++){
	    if($j%$k==0){
	    break;
	    }
	}
if($k==$j){
echo "prime no." .$j ."<br>";
}
}
echo "<br>";

for($j=1;$j<=$num;$j++){
    for($k=2;$k<$j;$k++){
	    if($j%$k==0){
	    break;
	    }
	}
if($k!=$j){
echo "non-prime no." .$j ."<br>";
}
}

Output:-

In the above Program using if condition and for loop statement with the modulous.

Looping Statement in PHP

Check on Facebook