title: How to echo specific multiple same records only once using foreach loops in PHP?
body: <p>I have these output using foreach loop in PHP. Right now the output inside foreach is like below.</p>
  
  <p>PHP code </p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;ACCOUNT NUMBER&lt;/th&gt;
        &lt;th&gt;CATEGORY&lt;/th&gt;
        &lt;th&gt;AMOUNT&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;?php
        $sqlTxt = "SELECT * FROM table WHERE column = 'Fruits' ";
        $sql = ORACLE::getInstance()-&gt;FetchArray($sqlTxt);
        if(count($sql) &gt; 0)
        {
          foreach($sql as $row)
          {
      ?&gt;
          &lt;tr&gt;
            &lt;td&gt;&lt;?php echo $row["ACCOUNT_NUMBER"] ;?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row["CATEGORY"]; ?&gt;&lt;/td&gt;
            &lt;td&gt;&lt;?php echo $row["AMOUNT"]; ?&gt;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;?php
          }
        }
      ?&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>And the output for above code is like this  </p>
  
  <pre><code>Account Number          Category            Amount
  1001                    Apple               30.00
  1001                    Mango               30.00
  1001                    Blueberry           30.00 
  
  1002                    Durian              40.00
  1002                    Pineapple           40.00
  1002                    Jackfruit           40.00 
  1002                    Lime                40.00
  
  1003                    Lemon               50.00
  1003                    Orange              50.00
  </code></pre>
  
  <p>My questions is how can I echo <strong>Account Number</strong> and <strong>Amount</strong> one time only while category keeps the looping ?</p>
  
  <p>My goal is to look like this. To add br tag after each comas.</p>
  
  <pre><code>Account Number          Category            Amount
  1001                    Apple,              30.00
                          Mango,              
                          Blueberry            
  
  1002                    Durian,             40.00
                          Pineapple,          
                          Jackfruit,           
                          Lime                
  
  1003                    Lemon,              50.00
                          Orange              
  </code></pre>
  
  <p>So far, what I have in my code is like this.</p>
  
  <p>PHP Code</p>
  
  <pre><code>&lt;table&gt;
    &lt;thead&gt;
      &lt;tr&gt;
        &lt;th&gt;ACCOUNT NUMBER&lt;/th&gt;
        &lt;th&gt;CATEGORY&lt;/th&gt;
        &lt;th&gt;AMOUNT&lt;/th&gt;
        &lt;/tr&gt;
    &lt;/thead&gt;
    &lt;tbody&gt;
      &lt;?php
        $sqlTxt = "SELECT * FROM table WHERE column = 'Fruits' ";
        $sql = ORACLE::getInstance()-&gt;FetchArray($sqlTxt);
        if(count($sql) &gt; 0)
        {
          $account_numbers = null;
          $categorys       = "";
          $amounts         = null;
  
          foreach($sql as $row)
          {
            if($row['ACCOUNT_NUMBER'] !== $account_numbers)
            {
              if ($account_numbers !== null)
              {
                echo '&lt;/td&gt;&lt;/tr&gt;';
              }
  
              echo "&lt;tr&gt;
                      &lt;td&gt;{$row['ACCOUNT_NUMBER']}&lt;/td&gt;
                      &lt;td&gt;{$row['CATEGORY']}";
            }
            else {
              echo "&lt;br&gt;{$selectionC['CATEGORY']}";
            }
            $account_numbers = $row['ACCOUNT_NUMBER'];
          }
              echo '  &lt;/td&gt;
                    &lt;/tr&gt;';
        }
      ?&gt;
    &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>I'm stuck here. Appreciate if someone can help me to solve this problem.</p>
  
  <p>Thanks.</p>