Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php median

function median($a) { 
    sort($a);
    $c = count($a);
    $m = floor(($c-1)/2);
    return ($c % 2) ? $a[$m] : (($a[$m]+$a[$m+1])/2);
}
echo median([1,6,4,2,4,6,10,12,19]); //6
 
PREVIOUS NEXT
Tagged: #php #median
ADD COMMENT
Topic
Name
8+2 =