Skip to content

Instantly share code, notes, and snippets.

@nathanbrauer
Created June 15, 2011 18:41
Show Gist options
  • Save nathanbrauer/1027787 to your computer and use it in GitHub Desktop.
Save nathanbrauer/1027787 to your computer and use it in GitHub Desktop.
<?php
//Predefined data:
//$Answers = array('1'=>15,'2'=>1,'5'=>21, ..., '1000000000'=>17); //k = answer, v = how many times that answer was chosen
$Question->PossibleAnswers = '{"min":"0","max":"1000000000","default":"2","unit":""}';
$PossibleAnswers = json_decode($Question->PossibleAnswers);
$diff = $PossibleAnswers->max - $PossibleAnswers->min;
$add = ceil($diff/100);
while ($PossibleAnswers->min <= $PossibleAnswers->max) {
$Possibility = $PossibleAnswers->min;
$PossibleAnswers->min += $add;
$want = array_flip(range($Possibility,$PossibleAnswers->min-1));
$AnswerPieces = array_intersect_key($want,$Answers);
if (empty($AnswerPieces)) continue;
$Columns[] = ($add == 1) ? $Possibility : $Possibility.' to '.($PossibleAnswers->min-1); //e.g. 10-19 if $add == 10
$Data[] = array_sum($AnswerPieces);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment