Median
This algorithm computes the median of the given set of numbers.
function Median($data)
{
$dataSize = count($data);
sort($data);
if ($dataSize % 2 == 0)
return ($data[$dataSize / 2 - 1] + $data[$dataSize / 2]) / 2;
else
return $data[$dataSize / 2];
}
Example
$data = array( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 );
$median = Median($data);
Output
5.5