<?php
// create class to easily add and store resolutions
class Resolution
{
public $x;
public $y;
}
// create our original resolution and calculate its aspect ratio
$origRes = new Resolution();
$origRes->x = 640;
$origRes->y = 480;
$originalRatio = ($origRes->x / $origRes->y);
// create valid resolution
$firstRes = new Resolution();
$firstRes->x = 1280;
$firstRes->y = 720;
// create another resolution
$secondRes = new Resolution();
$secondRes->x = 320;
$secondRes->y = 240;
// ...and so on; two are enough for the example
// you must learn about arrays and came up with proper solution how to populate them
// create array of resolutions from existing resolutions
$arrayOfRes = array($firstRes, $secondRes);
// another way of adding could be: $arrayOfRes[] = $thirdRes
// because floating point values aren't perfect on computers,
// we need some range value to check if the values are "close enough"
// in other words: it's our precision
$epsilon = 0.00001;
// iterate over all elements in array
foreach ($arrayOfRes as $res)
{
// calculate ratio
$ratio = $res->x / $res->y;
// abs - absolute value, thus always positive
// we check if difference is precise enough and print some text
if(abs($ratio - $originalRatio) < $epsilon) echo'print it here or do something';
}
?>