title: Highest multiplication with multiple and max number set
body: <p>Not quite sure what to set this title as, or what to even search for. So I'll just ask the question and hope I don't get too many downvotes.</p>
  
  <p>I'm trying to find the easiest way to find the highest possible number based on two fixed numbers.</p>
  
  <p>For example: </p>
  
  <p>The most I can multiply by is, say, 18 (first number). But not going over the resulted number, say 100 (second number).</p>
  
  <p>2 x 18 = 36</p>
  
  <p>5 x 18 = 90</p>
  
  <p>But if the first number is a higher number, the second number would need to be less than 18, like so:</p>
  
  <p>11 x 9 = 99</p>
  
  <p>16 x 6 = 96</p>
  
  <p>Here I would go with 11, because even though the second number is only 9, the outcome is the highest. The second number could be anything as long as it's 18 or lower. The first number can be anything, as long as the answer remains below 100. Get what I mean? </p>
  
  <p>So my question is, how would write this in php without having to use switches, if/then statements, or a bunch of loops? Is there some math operator I don't know about that handles this sort of thing?</p>
  
  <p>Thanks.</p>
  
  <p>Edit:</p>
  
  <p>The code that I use now is:</p>
  
  <pre><code>function doMath($cost, $max, $multiplier) {
      do {
        $temp = $cost * $multiplier;
        if ($temp &gt; $max) { --$multiplier; }
      } while ($temp &gt; $max);    
      return array($cost, $temp, $multiplier);
  }
  </code></pre>
  
  <p>If we look at the 11 * 9 = 99 example,</p>
  
  <p>$result = doMath(11, 100, 18);</p>
  
  <p>Would return,</p>
  
  <p>$cost = 11, $temp = 99, $multiplier = 9</p>
  
  <p>Was hoping there was an easier way so that I wouldn't need to use a loop, being as how there are a lot of numbers I need to check.</p>