I need a php function to take a list of numbers and to remove the numbers are not consistent. Example: 100 93 109 94 23 98 102 44 So the php function would output the new list without the inconsistent numbers 23 and 44
What do you define as consistent? This shouldn't be a difficult feat to accomplish. <?php $numbers = array(100,93,109,94,23,98,102,44); $total_numbers = count($numbers); $sum = 0; foreach($numbers as $number){ $sum = $sum + $number; } $average = $sum / $total_numbers; //what defines inconsistent? $inconsistent = 30; $range = $average - $inconsistent; $inconsistent_numbers = array(); foreach($numbers as $number){ if($number < $range){ $inconsistent_numbers[] = $number; } } ?> PHP: