title: PHP: Simple recursive function into iterative function
body: <p>I was going to do it in C but was confused, so I turned to PHP and was able to copy a recursive function to do this. I am converting an integer into a string with math. Here it is:</p>
  
  <pre><code>function intToString($myDecimal){
      if($myDecimal &lt; 10) {
          return $myDecimal;
      }
      return intToString(($myDecimal / 10)) . ($myDecimal % 10);
  }
  </code></pre>
  
  <p>I was able to convert a recursive factorial function before.. but with this I just have no clue.. My attempt is as follows:</p>
  
  <pre><code>function intToStringIter($myDecimal){
      $out = "";
      while($myDecimal &gt; 10) {
          $myDecimal /= 10;
          $out .= $myDecimal;
      }
      $out .= $myDecimal % 10;
      return $out;
  }
  </code></pre>
  
  <p>I think I am too tired to see the proper logic at the moment.. It returns 22 instead of 20, I cannot wrap my head around what is correct. Do you see what I am doing wrong?</p>