Easy To Learning
  • Login
  • Sign Up
  • Q&A
  • Home
  • Php Tutorial
  • MySql Tutorial
  • Object-Oriented Programming
  • Java Tutorial
  • HTML Tutorial
  • React JS Tutorials
  • Free Projects
  • Blogs & Articles
  • Others
    • About Us
    • Contact Us
Prime Number Program
Easy To Learning

Education Needs Complete Solution

Online Ask Question Question And Answer
  1. Home
  2. PHP Tutorials
  3. Prime Number Program

PHP Tutorial

Basic PHP Fundamentals

  • PHP Tutorial Content
  • PHP Introduction
  • PHP History
  • Uses of PHP
  • PHP Features
  • What Is PHP
  • PHP Installation And Software Requirements
  • How To Install Wamp Server
  • How To Install Xampp Server
  • Php Syntax
  • PHP Variables
  • PHP Data Types
  • PHP Constants
  • PHP Echo And Print
  • PHP Operators
  • PHP Assignment Operators
  • PHP String And Logical Operators
  • Operators Categories
  • PHP Comments
  • PHP $ And $$ Variables
  • Super Global Variables

PHP Control Statement

  • PHP Control Structure
  • PHP If Statement
  • If Elseif Statement In PHP
  • Switch Statement In PHP
  • Break Statement In PHP
  • If Elseif Else Statement
  • Continue Statement In PHP

Php Loops

  • What Is Loop
  • For Loop In PHP
  • PHP Foreach Loop
  • PHP While Loop
  • Do While Loop

PHP Arrays

  • PHP Arrays
  • Indexed Arrays
  • Associative Array
  • Multidimensional Arrays
  • Array Functions
  • Array Constants
  • List of Array Functions
  • Array Functions First Exercise

Php String

  • String In PHP
  • PHP String Functions

PHP Functions

  • PHP Functions
  • PHP Parameterized Function
  • PHP Call By Value
  • Call By Reference In PHP
  • Default Argument Values Function In PHP
  • Variable Argument Function In PHP
  • Recursive Function In PHP
  • Math Function In PHP
  • Math Function Examples

PHP Form

  • Form Handling In PHP

PHP Include

  • Include File In PHP

PHP State Management

  • Cookies In PHP
  • Session In PHP

PHP File System

  • File Handling In PHP
  • Open Files In PHP
  • Read Files In PHP
  • Write Files In PHP
  • Delete Files In PHP
  • Append To Files In PHP

PHP Upload & Download

  • File Upload In PHP
  • Download File In PHP

PHP Mail System

  • Mail System In PHP
  • Mail With Attachment In PHP

Basic PHP Program

  • Php Programs
  • Sum Of Digits
  • PHP Even Odd Program
  • Prime Number Program
  • Table Of Number Program
  • Factorial Of A Number
  • Armstrong Number
  • Palindrome Number
  • Fibonacci Series

Prime Number Program

How To Check Prime Number Using PHP

A number which is only divisible by 1 and itself is called a prime number. Numbers 2, 3, 5, 7, 11, 13, 17, etc. are prime numbers.

  • 2 is the only even prime number.
  • It is a natural number greater than 1 and so 0 and 1 are not prime numbers.

Prime number program using PHP

Example:

Write a program to check the first 15 prime numbers.

<?php 
$count = 0; 
$num = 2; 
while ($count < 15 ) 
{ 
$div_count=0; 
for ( $i=1; $i<=$num; $i++) 
{ 
if (($num%$i)==0) 
{ 
$div_count++; 
} 
} 
if ($div_count<3) 
{ 
echo $num." , "; 
$count=$count+1; 
} 
$num=$num+1; 
} 
?> 

Output: 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47


Prime Number using Form in PHP

Example:

We'll show a form, which will check whether a number is prime or not.

<form method="post"> 
Enter a Number: <input type="text" name="input"><br><br> 
<input type="submit" name="submit" value="Submit"> 
</form> 
<?php 
if($_POST) 
{ 
   $input=$_POST["input"]; 
   for ($i = 2; $i <= $input-1; $i++) { 
    if ($input % $i == 0) { 
    $value= True; 
    } 
} 
if (isset($value) && $value) { 
   echo "The Number ". $input . " is not prime"; 
} else { 
  echo "The Number ". $input . " is prime"; 
  }  
} 
?> 

Output:

On entering number 12, we get the following output. It states that 12 is not a prime number.

The Number 12 is not prime

Check 2: check number is a prime or not

On entering number 97, we get the following output. It states that 97 is a prime number.

The Number 97 is prime

Series: PHP Tutorials Hub
All Topics
Free Download Projects
Previous Chapter
Next Chapter

Ask a Question

Have a coding query or doubt? Ask here and get help from our community.

500 characters remaining
Submitting...
Free Download Projects
Join Telegram Group Join WhatsApp Group
Related Topics:
PHP Prime Number Program php tutorial example file session date array functions

Member Sign In

Forgot?
Signing in...

Don't have an account? Register here

Create Free Account

Register Captcha
Registering...

Already have an account? Sign In

Ask a Question

500 characters remaining
Submitting...

About Easy To Learning

Easy To Learning is a comprehensive programming learning portal offering free, practical, developer-driven tutorials for PHP, Java, Python, Spring, MySQL, CSS, Bootstrap, CakePHP, and more.

Explore community-contributed questions and answers, and download ready-to-run source code projects.

Quick Links

  • Home
  • Questions & Answers
  • Download Projects
  • Blog & Articles
  • Member Login

Community

  • Telegram Group
  • WhatsApp Community
  • Ask a Question
  • Join as Member

Connect With Us

Stay updated with our newest programming tutorials and free open source projects.

© 2026 Easy To Learning. All Rights Reserved.