PHP | Check if a number is armstrong number Last Updated : 30 Apr, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 every digit r in input number x, compute r3. If sum of all such values is equal to n, then print "Yes", else "No". Php <?php // PHP code to check whether a number is // armstrong number or not // function to check whether the number is // armstrong number or not function armstrongCheck($number){ $sum = 0; $x = $number; while($x != 0) { $rem = $x % 10; $sum = $sum + $rem*$rem*$rem; $x = $x / 10; } // if true then armstrong number if ($number == $sum) return 1; // not an armstrong number return 0; } // Driver Code $number = 407; $flag = armstrongCheck($number); if ($flag == 1) echo "Yes"; else echo "No" ?> Output: Yes Time Complexity: O(num), where num is the number of digits in the given number. Comment More infoAdvertise with us Next Article How to format Phone Numbers in PHP ? A ayushjauhari14 Follow Improve Article Tags : PHP Similar Reads PHP | Check if a number is Perfect number 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 i 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 How to format Phone Numbers in PHP ? In this article, we will learn how to format phone numbers using PHP. When we need to store a phone number then we store the formatting phone number. Using PHP, we can easily format phone numbers. Approach: In this article, we will format the phone number using the preg_match() method. We can use th 1 min read How to Convert Number to Character Array in PHP ? Given a number, the task is to convert numbers to character arrays in PHP. It is a common operation when you need to manipulate or access individual digits of a number. This can be particularly useful in situations where you need to perform operations on the digits of a number, such as digital root 3 min read How to convert a String into Number in PHP ? Strings in PHP can be converted to numbers (float/ int/ double) very easily. In most use cases, it won't be required since PHP does implicit type conversion. This article covers all the different approaches for converting a string into a number in PHP, along with their basic illustrations.There are 4 min read Like