title: if statement to skip foreach but still run code inside
body: <p>How can I run the code within the <code>foreach</code> loop when I only have one bank account, while avoiding duplicate code?</p>
  
  <pre><code>&lt;?php 
      if($_GET['bank_id']&gt;0){
          $id = ($_GET['bank_id']);
          $bank_account = BankAccounts::find_by_id($id); 
      }else{
          $bank_accounts = BankAccounts::find_all(); 
      }
  ?&gt;
  
      &lt;table class="bordered"&gt;
        &lt;tr&gt;
          &lt;th&gt;accounts id&lt;/th&gt;    
          &lt;th&gt;accounts name&lt;/th&gt;  
          &lt;th&gt;accounts number&lt;/th&gt;    
          &lt;th&gt;account&lt;/th&gt;    
        &lt;/tr&gt;
  
      &lt;?php 
      if(isset($bank_accounts)){
      foreach($bank_accounts as $bank_account){
          ?&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_id; ?&gt; &lt;/th&gt;  
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_name; ?&gt; &lt;/th&gt;    
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_number; ?&gt; &lt;/th&gt;  
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_account; ?&gt; &lt;/th&gt;  
        &lt;/tr&gt;
      &lt;?php
          } 
          }else{
      ?&gt;
          &lt;tr&gt;
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_id; ?&gt; &lt;/th&gt;  
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_name; ?&gt; &lt;/th&gt;    
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_accounts_number; ?&gt; &lt;/th&gt;  
          &lt;th&gt;&lt;?php echo $bank_account -&gt; bank_account; ?&gt; &lt;/th&gt;  
        &lt;/tr&gt;
   &lt;?php  } ?&gt;
      &lt;/table&gt;
  </code></pre>