- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP program to check if a number is prime or not
To check if a number is prime or not, the code is as follows −
Example
<?php function check_prime($num) { if ($num == 1) return 0; for ($i = 2; $i <= $num/2; $i++) { if ($num % $i == 0) return 0; } return 1; } $num = 47; $flag_val = check_prime($num); if ($flag_val == 1) echo "It is a prime number"; else echo "It is a non-prime number" ?>
Output
It is a prime number
A function named ‘check_prime’ is used to check if the number is prime or not. A number that needs to be checked for being prime is passed as a parameter to the function. The number is defined and this function is called by passing the number as parameter. Relevant message is displayed on the console.
- Related Articles
- C# Program to check if a number is prime or not
- Python program to check if a number is Prime or not
- Bash program to check if the Number is a Prime or not
- Write a C# program to check if a number is prime or not
- C++ Program to Check Whether a Number is Prime or Not
- C Program to Check Whether a Number is Prime or not?
- Java Program to Check Whether a Number is Prime or Not
- Check if a number is Quartan Prime or not in C++
- Check if a number is Primorial Prime or not in Python
- Check if a number is Primorial Prime or not in C++
- Python Program to Find if a Number is Prime or Not Prime Using Recursion
- Check if a number is a Pythagorean Prime or not in C++
- Write a Golang program to check whether a given number is prime number or not
- How to check whether a number is a prime number or not?
- 8085 program to determine if the number is prime or not

Advertisements