title: How do you avoid the same data in foreach, on sequential data?
body: <p>This is the data now</p>
  
  <blockquote>
    <p>string(3) "3.1"</p>
    
    <p>string(3) "3.2"</p>
    
    <p>string(3) "3.3"</p>
    
    <p>string(3) "3.4"</p>
    
    <p>string(3) "3.1"</p>
    
    <p>string(3) "3.2"</p>
  </blockquote>
  
  <p>And this is the data I want</p>
  
  <blockquote>
    <p>string(3) "3.1"</p>
    
    <p>string(3) "3.2"</p>
    
    <p>string(3) "3.3"</p>
    
    <p>string(3) "3.4"</p>
  </blockquote>
  
  <p>stop looping here</p>
  
  <blockquote>
    <p>string(3) "3.1"</p>
    
    <p>string(3) "3.2"</p>
  </blockquote>
  
  <p>and the following code that I made</p>
  
  <pre><code>&lt;?php 
  $tempData = null; 
  foreach ( $nilai as $key ) : 
    if( $tempData !== $key-&gt;no_kd ) :
        echo "&lt;pre&gt;"; var_dump($key-&gt;no_kd); echo "&lt;/pre&gt;";
        $tempData = $key-&gt;no_kd; 
     endif; 
  endforeach; 
  ?&gt;
  </code></pre>