anurag-singh
7/4/2015 - 1:22 PM

Find all the Prime numbers with the PHP function

Find all the Prime numbers with the PHP function

<?php

  function find_prime_nums($start, $end){
    for($i=$start; $i<=$end; $i++){
      $counter = 0;
      
      for($j=1; $j<=$i; $j++){
        if($i%$j == 0){
          $counter++;
        }
      }
      
      if($counter == 2) {
        echo "$i - is a prime number. <br/>";
      }
    }
  }
  
  find_prime_nums(2,10);
?>