• PHP Video Tutorials

PHP - Stats Stat Factorial() Function



Definition and Usage

The stats_stat_factorial() function can return the factorial of an integer.

Syntax

  float stats_stat_factorial( int $n )

Parameters

Sr.No Parameter Description
1

n

An integer

Return Values

The stats_stat_factorial() function can return the factorial of an integer, n.

Dependencies

This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial

Example

In the following example, we compute factorial of an integer 0.

<?php
   var_dump(stats_stat_factorial(0));
?>

Output

This will produce following result −

float(1)

Example

In the following example, we compute factorial of an integer 1.

<?php
   var_dump(stats_stat_factorial(1));
?>

Output

This will produce following result −

float(1)

Example

In the following example, we compute factorial of an integer 2.

<?php
   var_dump(stats_stat_factorial(2));
?>

Output

This will produce following result −

float(2)

Example

In the following example, we compute factorial of an integer 3.

<?php
   var_dump(stats_stat_factorial(3));
?>

Output

This will produce following result −

float(6)

Example

Following is an error case. In the following example, we pass empty parameter. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_stat_factorial());
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_stat_factorial() expects exactly 1 parameter, 0 given

bool(false)
Advertisements