Skip to content

Instantly share code, notes, and snippets.

@erikfrey
Created September 22, 2009 20:00
Show Gist options
  • Save erikfrey/191361 to your computer and use it in GitHub Desktop.
Save erikfrey/191361 to your computer and use it in GitHub Desktop.
$words = explode(" ",$trendResults['model_words']);
$weights = explode(" ",$trendResults['model_weight']);
$word_weights = array();
for ( $i = 0; $i <= sizeof($words); $i += 1) {
$word_weights[$i] = $weights[$i];
}
arsort($word_weights);
$wordLimit = 4;
$idxs = array();
foreach($word_weights as $index => $weight){
if ($wordLimit) {
$idxs[] = $index;
--$wordLimit;
}
}
foreach ($words as $idx => $word) {
if (in_array($idx, $idxs)) {
echo $word . " ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment