title: Remove duplicate from foreach loop
body: <p>I'm trying to loop through a custom post type and display all meta values for a meta key.</p>
  
  <p>I'm able to display all the values, however there are some duplicates. I want to remove those duplicates.</p>
  
  <p>I have tried using <code>array_unique</code> without luck.</p>
  
  <p>My code:</p>
  
  <pre><code>&lt;?php
  query_posts(array(
  'post_type' =&gt; 'lejlighed'
  
   ));
   ?&gt;
                 &lt;?php
  while (have_posts()):
  the_post();
  
  
  $meta = get_post_meta($post-&gt;ID, 'antal_varelser');
  
  foreach ($meta as $m) {
  
      echo '&lt;option value="1"&gt;' . $m . '&lt;/option&gt;';
  
  }
  endwhile;
  ?&gt; 
  </code></pre>
  
  <p>The result: 2 2 3 4 3 3 4</p>
  
  <p>My code with <code>array_unique</code>:</p>
  
  <pre><code>&lt;?php
  $the_query = new WP_Query(array(
  'post_type' =&gt; 'lejlighed',
   ));
   ?&gt;
   &lt;?php
  
   while ($the_query-&gt;have_posts()):
   $the_query-&gt;the_post();
   $meta = get_post_meta($post-&gt;ID, 'antal_varelser');
   $result = array_unique($meta);
  
   foreach($result as $r)
   {
   echo '&lt;option value="1"&gt;' . $m . '&lt;/option&gt;';
   }
  
   endwhile; ?&gt;
  </code></pre>
  
  <p>Outputs nothing.</p>
  
  <p><code>print_r($meta)</code> returns:</p>
  
  <pre><code>Array ( [0] =&gt; 2 ) Array ( [0] =&gt; 12 ) Array ( [0] =&gt; 4 ) Array ( [0] =&gt; 2 ) Array ( [0] =&gt; 5 ) Array ( [0] =&gt; 2 ) Array ( [0] =&gt; 4 ) Array ( [0] =&gt; 4 ) Array ( [0] =&gt; 3 ) Array ( [0] =&gt; 3 ) 
  </code></pre>
  
  <p>Any suggestions?</p>