## Posted By

Scooter on 01/03/09

# Perfect Numbers

/ Published in: PHP

Determine whether the given number is a perfect number.

`<?php    /*    Copyright (c) 2009, reusablecode.blogspot.com; some rights reserved.        This work is licensed under the Creative Commons Attribution License. To view    a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or    send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California    94305, USA.    */     // Determine whether the given number is a perfect number.    function isPerfect(\$number)    {        // Only positive integers can be perfect.        if (\$number < 1)        {            return false;        }         // Calculate the factors for the given number.        for(\$i = 1; \$i <= \$number; \$i++)        {            if (\$number % \$i == 0)            {                \$arrFactors[] = \$i;            }        }         // A perfect number is a number that is half the sum of all of its positive divisors (including itself).        return (\$number == array_sum(\$arrFactors) / 2) ? true : false;    }?>`