I am trying to sort my results by a number value which is calculated OUTSIDE of the array - I see that other questions have been asked similar to mine but none mention sorting by a value given OUTSIDE of the array. I am currently trying to use SPL, but it does not sort results by highest to lowest - I am not sure why. Any thoughts would be appreciated.
class SimpleHeapSort extends SplMaxHeap {
public function compare($a, $b) {
return strcmp($a, $b);
}
}
$r_array = array();
$obj = $this->request_data->d->results;
$ic = count($obj);
print("<table cellspacing=10>");
for($i=0;$i<$ic;$i++){
$r_array[$i] = array('Title'=>$obj[$i]->Title,'Description'=>$obj[$i]->Description,'Url'=>$obj[$i]->Url);
$fb_likes[$i] = reset($this->get_fb_likes($r_array[$i]['Url']) );
$heap = new SplMaxHeap();
$heap->insert($fb_likes[$i]->total_count);
foreach($heap as $number) {
echo "<tr><td>".$r_array[$i]['Title']."</td>";
echo "<td>".$r_array[$i]['Description']."</td>";
echo "<td>".$r_array[$i]['Url']."</td>";
echo "<td>fb" . $number . "</td></tr>";
}
}
print("</table>");
I would like to sort my results (highest to lowest) by $fb_likes->total_count
- this is a number/integer. This value is calculated OUTSIDE of $r_array[$i]
. How can I go about sorting each result from highest to lowest $fb_likes->total_count
number value?
While I am currently trying to use SPL, I am open to any alternatives as well.
Thank you in advance for any help.