Oihana PHP

median.php

Table of Contents

Functions

median()  : float
Computes the median (middle value) of a list of numbers.

Functions

median()

Computes the median (middle value) of a list of numbers.

median(array<int, int|float> $values) : float

The values are sorted numerically. For an odd number of values the middle one is returned ; for an even number, the average of the two central values is returned.

Parameters
$values : array<int, int|float>

A non-empty list of numeric values.

Tags
throws
InvalidArgumentException

If the array is empty.

example
use function oihana\core\maths\median;

echo median( [ 3 , 1 , 2 ] )     ; // 2.0
echo median( [ 4 , 1 , 3 , 2 ] ) ; // 2.5
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
float

The median of the values.

On this page

Search results