• PHP Video Tutorials

PHP - Stats Stat Percentile() Function



Definition and Usage

The stats_stat_percentile() function can return the percentile value.

Syntax

  float stats_stat_percentile( array $arr, float $perc )

Parameters

Sr.No Parameter Description
1

arr

The input array

2

perc

The percentile

Return Values

The stats_stat_percentile() function can return the perc-th percentile value of the array arr.

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 50-th percentile value of the array.

<?php
   var_dump(stats_stat_percentile(array(1, 3, 2, 4), 50));
?>

Output

This will produce following result −

float(2)

Example

In the following example, we compute 50-th percentile value of the array.

<?php
   var_dump(stats_stat_percentile(array(1, 3, 5, 2, 4), 50));
?>

Output

This will produce following result −

float(3)
Advertisements