title: How to add fractions and display the result as fraction?
body: <pre><code>public function add($temp) {
          $newNum = $this-&gt;num + $temp-&gt;num;
          if($this-&gt;denum == $temp-&gt;denum) {
                 // add two fractions having same denominator
                 $answer = $newNum . "/" . $this-&gt;denum;
          } else {
                 // how to add two fractions having different denominator?
          }
          return $answer;
  }
  </code></pre>
  
  <p>In other words, how to handle the case of two fractions having different denominators, like:</p>
  
  <blockquote>
    <p>1/3 + 1/6 = 3/6</p>
  </blockquote>
  
  <p>or</p>
  
  <blockquote>
    <p>1/3 + 1/5 = 8/15</p>
  </blockquote>