title: Loop through and compare
body: <p>I have this code here the product tags can be animals, life or market. What I am trying to do is separate their list, but this code creates a new <code>ul</code> for every tag after animals and I do not know why, can anyone help?:</p>
  
  <pre><code>&lt;?php
  
  $versionvalues = get_the_terms( $product-&gt;id, 'product_tag');
  
  if($versionvalues){
          $previousTag = 'animals';
          foreach ( $versionvalues as $versionvalue ) { 
  
                  $currentTag = $versionvalue-&gt;name;
  
  
                  if($currentTag != $previousTag){
  
                          echo '&lt;/ul&gt;&lt;ul class="products" style="text-align:center;"&gt;';
                          $previousTag = $currentTag;
                  }else{
                          $previousTag = $currentTag;
                  }
  
  
  
         } 
  }
  
  ?&gt;
  </code></pre>
  
  <p>Maybe wordpress doesn't allow me to put get_the_terms values into a variable. I did an echo of the $previousTag in the loop is keeps returning animals.</p>
  
  <p>I have realized that is code is inside my woocommerce loop for my products, so <code>$versionvales</code> gets updated for each product and <code>$previousTag</code> will also reset to animals for each product.</p>