“Armstrong Number Program” is the initial program from where most of the beginner developers will start to learn and write code in any language. An Armstrong number is a number that is the sum of its own digits each raised to the power of the number of digits is equal to the number itself. Here is an example of check a armstrong number in PHP. Armstrong Number Program :- Below is the simple PHP program to check a number armstrong. <?php $number=153; $sum=0; $temp=$number; while($temp!=0) { $reminder=$temp%10; $sum=$sum+$reminder*$reminder*$reminder; $temp=$temp/10; } if($number==$sum) { echo “It…
Category: Useful PHP Programs
Prime Number Program in PHP
Prime Number :- A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 3 is a prime number because it has no positive divisors other than 1 and 3. Prime numbers are below:- 2, 3, 5, 7, 11, 13, 17, 19 …. Here I am writing the PHP program to check whether a number is Prime or not. <?php function CheckPrime($number){ for($x=2;$x<$number;$x++){ if($number%$x == 0){ return 0; } } return 1; } $a = CheckPrime(17); if ($a==0) echo ‘This is not…
Palindrome Number Program in PHP
Palindrome Number :- A palindromic number or numeral palindrome is a number that remains the same when its digits are reversed. Like 53235, Below are the example palindrome number:- 121 , 212 , 12321 , 16461 #Steps to Check a Palindrome Number :- Take a Number Now reverse its digit Now compare both the numbers if both are equals to each other then return “Number is Palindrome“. else return “Number is not Palindrome“ Here I am writing the PHP program to check whether a number is palindrome or not. Palindrome Number Program Without of Using PHP…
Fibonacci Series in PHP
Fibonacci series means to get next term by adding its previous two numbers. For an example:- 0 1 1 2 3 5 8 13 21 Here I am writing the PHP program to print Fibonacci Series. <?php function printFabonacciSeries($number){ $a = 0; // first number of series $b = 1; // second number of series echo ‘Fabonacci Series <br/>’; echo $a.’ ‘.$b; for($i=2;$i<$number;$i++){ $c = $a + $b; //print next number of series echo ‘ ‘.$third; $a = $b; $b = $c; } } printFabonacciSeries(9); ?> Output :- 0 1 1 2 3 5 8 13 21 Alternate Way…
Factorial Program in PHP
image source : google images The factorial of number n is multiplying given integer with the sequence of its descending positive integers. we denoted the factorial of a number n by n! in mathematics. Here I am writing factorial program in PHP.. Example :- 5! = 5*4*3*2*1 = 120 7! = 7*6*5*4*3*2*1 = 5040 Here are writing the PHP program to find a factorial of a number. <?php function factorial($number){ $factorial = 1; for($x=$number;$x>=1;$x–){ $factorial = $factorial*$x; } return $factorial; } echo ‘factorial is=’.factorial(11); ?> Output :- factorial…