public function _determineSnipLocation($locations, $prevcount)
{
if (!isset($locations[0])) {
return -1;
}
// If we only have 1 match we dont actually do the for loop so set to the first
$startpos = $locations[0];
$loccount = count($locations);
$smallestdiff = PHP_INT_MAX;
// If we only have 2 skip as its probably equally relevant
if (count($locations) > 2) {
// skip the first as we check 1 behind
for ($i = 1; $i < $loccount; $i++) {
if ($i == $loccount - 1) {
// at the end
$diff = $locations[$i] - $locations[$i - 1];
} else {
$diff = $locations[$i + 1] - $locations[$i];
}
if ($smallestdiff > $diff) {
$smallestdiff = $diff;
$startpos = $locations[$i];
}
}
}
$startpos = $startpos > $prevcount ? $startpos - $prevcount : 0;
return $startpos;
}