Forum Moderators: coopster
I am writing a meta search engine script and each results gets a score based on a number of factors. What I'm trying to do is sort the results with the highest score first, ready for output.
So the Array looks like this
array(2) {
[0]=> array(4) {
[Title]=> "My site"
[Description]=> "whatever"
[Url]=> "url.com"
[Score]=> "200"
}
[1]=> array(4) {
[Title]=> "My site2"
[Description]=> "whatever"
[Url]=> "url.com"
[Score]=> "223"
}
}
Obviuosly there are more than 2 results in real life, but is there anyway to sort the array so My Site2, with a score of 223 will appear first? Thanks For Reading
I remember it being a bit tricky but it looks like there is a much better description there now.
function cmp($a, $b) {
return ($a['Score'] == $b['Score']) ? 0 : (($a['Score'] > $b['Score']) ? -1 : 1);
}
uasort [php.net]($array, 'cmp');