Is Perfect Number
This algorithm checks whether a given number is perfect number or not. Perfect number is a number which is equal to sum of its divisor. For example divisors of 6 are 1,2 and 3. The sum of these divisors is 6. So 6 is called as perfect number.
function IsPerfectNumber($number)
{
$sum = 0;
$i = 1;
while ($i < $number)
{
if ($number % $i == 0)
$sum += $i;
$i++;
}
return $sum == $number;
}
Example
$isPerfectNumber = IsPerfectNumber(28);
Output
True