Table of Contents

What we are going to see through this article is Check Given Number Is Disarium Number In PHP. A Disarium number is said to be when a number is equal to the sum of its digits elevated to the power of the respective levels.

For example, If our input number is 135 then the output will be like shown below:(135=1^1+3^2+5^3=1*1+3*3+5*5*5=1+9+125=135).

## Check Given Number is Disarium Number in PHP

```
<!DOCTYPE html>
<html>
<body>
```**<?php**
//calculateLength() will count the digits present in a number
function calculateLength($n){
$length = 0;
while($n != 0){
$length = $length + 1;
$n = intval($n/10);
}
return $length;
}
$num = 135;
$rem = $sum = 0;
$len = calculateLength($num);
//Makes a copy of the original number num
$n = $num;
//Calculates the sum of digits powered with their respective position
while($num > 0){
$rem = $num%10;
$sum = $sum + pow($rem,$len);
$num = intval($num/10);
$len--;
}
//Checks whether sum is equal to the number itself
if($sum == $n)
print($n . " is a disarium number");
else
print($n . " is not a disarium number");
**?>**
</body>
</html>

## Output

A Disarium number is a sum of its digits equal to the power of the respective state.

`135 is a disarium number`

Read Also: Find ASCII Value Of Character Using PHP

## Final Words

What we learned through this article is to Check Given Number Is Disarium Number In PHP. Also if you have any doubts please leave a comment via the comment box. And we ask that you benefit everyone who shared this article with your friends.