About 1,720,000 results
Open links in new tab
  1. PHP | Check if a number is prime - GeeksforGeeks

    Jul 2, 2024 · In this article we will learn about how to check if a number is prime or not in PHP. Examples: A simple solution is to iterate through all numbers from 2 to n/2 and for every number check if it divides n. If we find any number that divides, we return 0 (false) otherwise we will return 1 (true). Below is the implementation of this approach in PHP:

  2. Check if a number is prime or not in PHP - CodeSpeedy

    The steps to check if a given number is prime or not using PHP. Algorithm: First we have to create an HTML code to accept input as we can’t accept input directly by PHP.

  3. Check If a Number Is Prime in PHP - Online Tutorials Library

    Learn how to check if a number is prime using PHP with this simple guide. Understand the logic and implementation of prime number checking.

  4. PHP - check if number is prime - Stack Overflow

    Jun 24, 2016 · You can check number is prime or not & without using loop with this function: function is_prime($p) { $r1 = $p%2; $r2 = $p%3; $r3 = $p%5; return ($p > 1) && (($r1 >= 1) && ($r2 >= 1) && ($r3 >= 1)) || in_array($p, [2,3,5]); }

  5. PHP Program to Print Prime Number from 1 to N - GeeksforGeeks

    Dec 27, 2023 · Given a number N, the task is to print all prime numbers in a range from 1 to N in PHP. Examples: First, take the number N as input. Then check for each number to be a prime number. If it is a prime number, print it. Example: This approach optimizes the brute force method by avoiding redundant checks. Example:

  6. How to Check Whether a Number is Prime in PHP - W3docs

    Imagine a given number and you want to check whether it is prime or not with PHP. Below, we will represent two methods: a simple method and a more efficient one. Read on to explore them.

  7. PHP: Check if a number is a prime number - Sling Academy

    Jan 9, 2024 · In PHP, this requires looping through potential divisors and determining if the number is divisible by any other numbers besides 1 and itself. The simplest way to check for a prime number in PHP is to use a for loop that attempts to divide the number by every smaller number starting from 2: if ($number <= 1) { return false;

  8. PHP Program to Check Prime Number | CodeToFun

    Oct 31, 2024 · The program defines a function isPrime that checks if a given number is prime. Inside the function, it checks for divisibility up to the square root of the number. The main section displays prime numbers in the range from 1 to 20 using a loop and the isPrime function.

  9. PHP Program to Check Prime Number - AlphaCodingSkills - Java

    In the example below, a function called primenumber () is created which takes a number as argument and checks it for prime number by dividing it with all natural numbers starting from 2 to N/2. function primenumber($MyNum) { . $n = 0; for($i = 2; $i < ($MyNum/2+1); $i++) { if($MyNum % $i == 0){ . $n++; break; } } if ($n == 0){ .

  10. PHP| Function to Check if a number is prime or not

    Dec 20, 2022 · In this post, we are going to learn how to write a program to check whether the given number is prime or not, using a function and displaying the result on the screen in the PHP programming language. Code to check prime number Check the …

  11. Some results have been removed
Refresh