I have an array of numbers and some numbers are obviously too big or too small relative to them all. I wonder if there is already some kind of function or algorithm that I can use in order to remove these records from array.
Here is an example of array
8
7
21
1330829238608
6
7
188
8
25
92433
19
6
At the moment all I can think about is just check if number is more than 1k or less than 1k and then do not allow it. But still I get problem since 188 does not belong here either.
Is there any good way that I can get majority of close numbers from this array and produce something like
8
7
6
7
8
6
This is what I have so far
<?php
echo '<pre>';
$startArray = Array(8, 7, 21, 1330829238608, 6, 7, 188, 8, 25, 92433, 19, 6);
print_r($startArray);
for ($i = 0; $i < count($startArray); $i++) {
if ($i != count($startArray) - 1) {
if ($startArray[$i] - 10 <= $startArray[$i + 1]) {
echo $startArray[$i] . '<br />';
}
}
}
This can be optimized but this is what I figured out, works with diff of 20%, you can change it to whatever % you want, of course.