计算php中的平均值,消除那些搞砸了所有平均值的数据

I want to calculate average of time spent on each task

But while calculating the average i dont want to count those time for average which is taking very long amount of time.

Lets say we have 5 task:

Task 1 takes 500 seconds
Task 2 takes 300 seconds
Task 3 takes 4000 seconds
Task 4 takes 450 seconds
Task 5 takes 500 seconds

If we calculate the average the result will be 1150 seconds.

But i want to eliminate those data from average calculation due to which the average is screwed up (4000 in this example). The reason for this is it may be possible that we don't have enough resource to complete the task at that time and taking longer because we are waiting for that resource.

You could loop through each task and only add its time value to the total count for averaging if it is less than whatever your preferred maximum would be. Use the counter you use for the loop and set another counter to count when one gets skipped. The divider would be the total count minus the second counter.