title: How to remove duplicate values from array in foreach loop?
body: <p>I want to remove duplicate values from array. I know to use <code>array_unique(array)</code> function but faced problem in <code>foreach</code> loop. This is not a duplicate question because I have read several questions regarding this and most of them force to use <code>array_unique(array)</code> function but I have no idea to use it in <code>foreach</code> loop. Here is my php function.</p>
  
  <pre><code>$images = scandir($dir);
  $listImages=array();
  foreach($images as $image){
      $listImages=$image;
      echo substr($listImages, 0, -25) ."&lt;br&gt;"; //remove last 25 chracters
  }
  </code></pre>
  
  <p>How to do this?        </p>