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)); } Quote 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. Quote 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); Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.