title: Using If Else with Foreach in Codeigniter
body: <p>Hi guys I use codeigniter to perform, conditioning on the View script but to no avail.
  Can I help correct correct code writing in the code below?</p>
  
  <p>My logic is:
  If the total "amount" in the "InvoiceDash" function is equal to 0,
  Then show the foreach function of the "resultAcumulativeSales" function,
  If it does not show the foreach function of the "resultAll" function                                        </p>
  
  <pre><code>&lt;?php foreach ($hasilInvoiceDash as $data) :
                                                  $x = $data-&gt;amount; 
                                                  endforeach;
  
                                                  if ($x = 0) { foreach ($hasilAcumulativeSales as $data) : $a = $data-&gt;sales;
                                                                      $b = 30 ;
                                                                      $c = $b*$a/100  ; 
                                                                      $d =  $a - $c ; ?&gt;
  
                                                                      &lt;?php if ($a &lt; "1") { ?&gt;
                                                                          &lt;h2 class="m-b-0"&gt; &lt;?php echo "0"; ?&gt; &lt;/h2&gt;
                                                                      &lt;?php } else { ?&gt;
                                                                          &lt;h2 class="m-b-0"&gt; &lt;?php echo $d ; ?&gt; &lt;/h2&gt;
                                                                      &lt;?php } endforeach;  ?&gt;
  
  
                                          &lt;?php } else{ foreach ($hasilSemua as $data) : ?&gt;
  
                                              &lt;h2 class="m-b-0"&gt;Rp. &lt;?php  
                                                   $a = $data-&gt;total_sales;
                                                   $b = 30 ;
                                                   $c = $b*$a/100  ; 
                                                   $d =  $a - $c ;
                                                   echo $d ; ?&gt; &lt;/h2&gt;
                                              &lt;?php endforeach; ?&gt; 
                                              &lt;?php } ?&gt;
  </code></pre>