Secure index access and type safe comparision in statistic median

This commit is contained in:
Arkadiusz Kondas 2016-12-06 08:59:34 +01:00
parent 6d11116994
commit 38a26d185f
1 changed files with 2 additions and 2 deletions

View File

@ -34,11 +34,11 @@ class Mean
self::checkArrayLength($numbers);
$count = count($numbers);
$middleIndex = floor($count / 2);
$middleIndex = (int)floor($count / 2);
sort($numbers, SORT_NUMERIC);
$median = $numbers[$middleIndex];
if (0 == $count % 2) {
if (0 === $count % 2) {
$median = ($median + $numbers[$middleIndex - 1]) / 2;
}