Alex Posted November 17, 2009 Share Posted November 17, 2009 Then just round the return using round()? function getAverage($arr) { asort($arr); array_shift($arr); array_shift($arr); return round(array_sum($arr) / count($arr)); } Link to comment https://forums.phpfreaks.com/topic/181302-solved-calculating-array/page/2/#findComment-959264 Share on other sites More sharing options...
kaveman50 Posted November 17, 2009 Author Share Posted November 17, 2009 Sorry I meant dropping the 2 lowest scores. Link to comment https://forums.phpfreaks.com/topic/181302-solved-calculating-array/page/2/#findComment-959315 Share on other sites More sharing options...
Alex Posted November 17, 2009 Share Posted November 17, 2009 I feel like we're going in circles. The function already removes the two lowest elements. That's the point of 'array_shift($arr); array_shift($arr);'. The array is already sorted from lowest to highest and array_shirt() removes the first element. Alternatively you could use do array_splice($arr, 0, 2); Link to comment https://forums.phpfreaks.com/topic/181302-solved-calculating-array/page/2/#findComment-959345 Share on other sites More sharing options...
kaveman50 Posted November 18, 2009 Author Share Posted November 18, 2009 Thanks! The splice worked. I'm not sure why the shift wasn't working. Anyways, no more questions on this program again I promise. Link to comment https://forums.phpfreaks.com/topic/181302-solved-calculating-array/page/2/#findComment-959680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.