sorting a list of objects by value php
- by Mike
I have a list of objects:
class Beer {
var $name;
var $id;
var $style;
var $brewery;
var $rate;
function getName() {
return $this->name;
}
function getID() {
return $this->id;
}
function getStyle() {
return $this->style;
}
function getBrewery() {
return $this->brewery;
}
function getRate() {
return $this->rate;
}
}
After doing some research online on how to accomplish this, this is my code:
usort($localBeersList, "cmp");
function cmp($a, $b)
{
if ($a->getRate() == $b->getRate()) {
return 0;
}
return ($a->getRate() < $b->getRate()) ? -1 : 1;
}
If I try and output my list after this I do not get anything.