fork(1) download
  1. <?php
  2.  
  3. // create class to easily add and store resolutions
  4. class Resolution
  5. {
  6. public $x;
  7. public $y;
  8. }
  9.  
  10. // create our original resolution and calculate its aspect ratio
  11. $origRes = new Resolution();
  12. $origRes->x = 640;
  13. $origRes->y = 480;
  14. $originalRatio = ($origRes->x / $origRes->y);
  15.  
  16. // create valid resolution
  17. $firstRes = new Resolution();
  18. $firstRes->x = 1280;
  19. $firstRes->y = 720;
  20.  
  21. // create another resolution
  22. $secondRes = new Resolution();
  23. $secondRes->x = 320;
  24. $secondRes->y = 240;
  25.  
  26. // ...and so on; two are enough for the example
  27. // you must learn about arrays and came up with proper solution how to populate them
  28.  
  29. // create array of resolutions from existing resolutions
  30. $arrayOfRes = array($firstRes, $secondRes);
  31.  
  32. // another way of adding could be: $arrayOfRes[] = $thirdRes
  33.  
  34. // because floating point values aren't perfect on computers,
  35. // we need some range value to check if the values are "close enough"
  36. // in other words: it's our precision
  37. $epsilon = 0.00001;
  38.  
  39. // iterate over all elements in array
  40. foreach ($arrayOfRes as $res)
  41. {
  42. // calculate ratio
  43. $ratio = $res->x / $res->y;
  44.  
  45. // abs - absolute value, thus always positive
  46. // we check if difference is precise enough and print some text
  47. if(abs($ratio - $originalRatio) < $epsilon)
  48. echo'print it here or do something';
  49. }
  50. ?>
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
print it here or do something