adspace
Answer Posted / Suresh Kumar Patel
A prime number is a positive integer greater than 1 that has no positive divisors other than 1 and itself. Here's a simple PHP function for checking if a given number is prime:
```php
function is_prime($num) {
if ($num <= 1) {
return false;
}
for ($i = 2; $i < sqrt($num); $i++) {
if ($num % $i === 0) {
return false;
}
}
return true;
}
```
This function checks all numbers up to the square root of the input number (since a larger factor of the number would be smaller than its square root) and returns `true` if the number is prime, otherwise `false`.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Explain me is it possible to destroy a cookie?
List some features of php that are deprecated in php7?
How to create a web form?
Tell me what kind of things have you done on the social side?
What is the current stable version of php? What advance thing in php7?
How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain
sort term descripttion form, report and uery
Write a program using while loop?
What is the difference between htmlentities() and htmlspecialchars()?
if you run the app program all vendor open items are cleared but is it possible to reverse the again again open items please tell me the answer
hello all, I need some sample placement papers in lion bridge.. can anyone help me?
What is trait in php?
how to detect a mobile device using php
What sized websites have you worked on in the past?
What is difference between static and final in php?