Averages/Median: Difference between revisions
Content deleted Content added
m →{{header|Haskell}}: remove URL from libheader invocation |
→{{header|PHP}}: Fix PHP example |
||
Line 630:
=={{header|PHP}}==
This solution uses the sorting method of finding the median.
<lang php>
function median($arr)
{
sort($arr);
$count = count($arr); //count the number of values in array
$middleval = floor(($count-1)/2); // find the middle value, or the lowest middle value
Line 642 ⟶ 644:
$median = (($low+$high)/2);
}
}
echo median(array(4.1, 5.6, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n"; // 4.4
echo median(array(4.1, 7.2, 1.7, 9.3, 4.4, 3.2)) . "\n"; // 4.25
</lang>
|