note 24052 modified in ref.math by aidan
| From: | aidan@php.net | Date: | Sat, 26 Jun 2004 03:13:38 +0000 |
| Subject: | note 24052 modified in ref.math by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-71710@lists.php.net to get a copy of this message | ||
The example for Factorials given above is wrong. Here a correct version, so that you do not have to
reinvent the wheel again...
<?php
function mathFact( $s )
{
$r = (int) $s;
if ( $r < 2 )
$r = 1;
else {
for ( $i = $r-1; $i > 1; $i-- )
$r = $r * $i;
}
return( $r );
}
?>
--was--
The example for Factorials given above is wrong. Here a correct version, so that you do not have to
reinvent the wheel again...
function mathFact( $s )
{
$r = (int) $s;
if ( $r < 2 )
$r = 1;
else {
for ( $i = $r-1; $i > 1; $i-- )
$r = $r * $i;
}
return( $r );
}
http://php.net/manual/en/ref.math.php