About 11,200,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. 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.

  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. 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.

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

    Dec 27, 2023 · Print Prime Numbers using PHP for Loop. First, take the number N as input. Then use a for loop to iterate the numbers from 1 to N; Then check for each number to be a prime number. If it is a prime number, print it. Example: PHP

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

    Jun 24, 2016 · You can find prime numbers and non prime numbers from 1 to your limit and its count.

  7. PHP Program to Check Prime Number | CodeToFun

    Oct 31, 2024 · Run the script to see whether the number is a prime number. The program defines a function isPrime that takes an integer as input and returns a boolean indicating whether the number is prime. Inside the function, it checks if the number is less than or equal to 1; if …

  8. 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){ .

  9. PHP function Exercises: Check whether a number is prime or not

    Dec 20, 2024 · Write a PHP function to check whether a number is prime or not. Note: A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. Visual Presentation: Sample Solution: PHP Code: // Loop through all numbers from 2 to n-1. for ($x = 2; $x < $n; $x++)

  10. Prime Number Program Using PHP | How to check if a number is Prime

    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. Write a program to check the first 15 prime numbers. $num = 2; .

  11. Some results have been removed
Refresh