PHP | Check if a number is Perfect number Last Updated : 14 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report A perfect number is a number if it is equal to the sum of its factors,that is original number is equal to sum of all its factors excluding the number itself. We have already discuss how to check if a number is perfect or not in this article. In this article we will discuss about how to do the same in PHP. Examples: Input : 6 Output : Perfect Number Explanation: factors of 6 are 1, 2, 3, 6 sum of its factors (excluding the number itself) = 1 + 2 + 3 = 6 Input : 24 Output : Not Perfect Number Explanation : factors of 24 are 1,2,3,4,6,8,12,24 sum of its factors(excluding the number itself) = 1 + 2 + 3 + 4 + 6 + 8 + 12 = 36 The idea to this is we will traverse through each number in the range [1,N) and check if it is a factor of the given number N. If it is a factor, we will add this number to a variable $sum. At the end is the variable $sum is equal to the original number then the given number is a Perfect Number. Below is the implementation of above idea in PHP: PHP <?php // Function to check if a number is perfect function isPerfectNumber($N) { // To store the sum $sum = 0; // Traversing through each number // In the range [1,N) for ($i = 1; $i < $N; $i++) { if ($N % $i == 0) { $sum = $sum + $i; } } // returns True is sum is equal // to the original number. return $sum == $N; } // Driver's code $N = 6; if (isPerfectNumber($N)) echo " Perfect Number"; else echo "Not Perfect Number"; ?> Output: Perfect Number Comment More infoAdvertise with us Next Article Check if a number is Full Prime A akash7981 Follow Improve Article Tags : Misc Web Technologies PHP school-programming PHP-basics +1 More Practice Tags : Misc Similar Reads PHP | Check if a number is armstrong number Given a number, we need to check whether it is an armstrong number or not in PHP. An Armstrong number is the one whose value is equal to the sum of the cubes of its digits.Examples: Input : 407 Output : Yes 407 = (4*4*4) + (0*0*0) + (7*7*7) = 64 + 0 + 343 = 407 Input : 303 Output : No Approach: For 2 min read PHP | Check if a number is prime A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The smallest prime number is 2, which is the only even prime number. All other even numbers are not prime because they are divisible by 2.2 is prime because it can only be divided by 1 and 2.3 is 3 min read PHP check if a number is Even or Odd Checking if a number is even or odd involves determining whether the number is divisible by 2. An even number has no remainder when divided by 2, while an odd number has a remainder of 1. This can be done using various methods like modulo or bit manipulation.Examples :Input : 42 Output : Even Explan 3 min read Check if a number is Full Prime A full prime number is one in which the number itself is prime and all its digits are also prime. Given a number n, check if it is Full Prime or not.Examples : Input : 53 Output : Yes Explanation: Number 53 is prime and its digits are also prime. Input : 41 Output : No Explanation: Number 41 is prim 7 min read Check Whether a Given Number is Ugly Number or Not in PHP Given an integer N, the task is to find out whether the given number is an Ugly number or not. Ugly numbers are numbers whose only prime factors are 2, 3 or 5.Examples: Input: N = 14 Output: No Explanation: 14 is not ugly since it includes another prime factor 7.Input: N = 6 Output: Yes Explanation: 3 min read Check whether the given array is perfect or not There is an array containing some non-negative integers. Check whether the array is perfect or not. An array is called perfect if it is first strictly increasing, then constant and finally strictly decreasing. Any of the three parts can be empty. Examples: Input : arr[] = {1, 8, 8, 8, 3, 2}Output : 5 min read Like