I have come across a conundrum which I usually just use a bunch of ifs or a switch.
To put this in perspective, the current project I am working on involves comparing the width and height of an image to get a number to determine if the width is longer than the height or the same.
Here is my code so far:
private function compare($width, $height)
{
return $width - $height;
}
This works as you might expect.
What I would like to find out is if there is a better way to do this:
if($this->compare($this->width, $this->height) == 0)
{
}
if($this->compare($this->width, $this->height) < 0)
{
}
if($this->compare($this->width, $this->height) > 0)
{
}
Thanks
Aucun commentaire:
Enregistrer un commentaire