Skip to content

Instantly share code, notes, and snippets.

@chadsten
Last active December 17, 2016 06:03
Show Gist options
  • Save chadsten/d7bc43e2bcfade5bcbe406cfa1559545 to your computer and use it in GitHub Desktop.
Save chadsten/d7bc43e2bcfade5bcbe406cfa1559545 to your computer and use it in GitHub Desktop.
<?php
function adjust_for_variance($price_array, $variance_threshold) {
$variance = calculate_variance($price_array);
if ($variance > $variance_threshold) {
sort($price_array);
array_pop($price_array);
$price_array = adjust_for_variance($price_array, $variance_threshold);
} else {
return $price_array;
}
}
function calculate_variance($price_array) {
if (is_array($price_array)) {
return round(((max($price_array) - min($price_array)) / (array_sum($price_array) / count($price_array)) * 100), 3);
} else {
return "<span class='nan'></span>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment