title: php generate random image from a directory
body: <p>I have to generate random image from a directory. I know which is simple like,</p>
  
  <pre><code>   $dire="images/";
     $images = glob($dire. '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
     $randomImage = $images[array_rand($images)];
     &lt;input type="image" src="&lt;?=$randomImage;?&gt;" alt="&lt;?=$randomImage;?&gt;" /&gt;
  </code></pre>
  
  <p>But I have to make sure that each image from that directory picked at least one time before generating second time randomly. The above code only will display only any random image. </p>
  
  <p>My thought is, I have to store the random image in an array and check the array every time with newly created random image. If the new random image is not in that array, I need to display that image,else I have to find another image.</p>
  
  <p>I created the below code with above thought. </p>
  
  <pre><code>  $allimgs=array();
    $dire="images/";
    $images = glob($dire. '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
    $randomImage = $images[array_rand($images)];
  
     if(!in_array($randomImage,$allimgs))
     {
       $allimgs[]=$randomImage;
       &lt;input type="image" src="&lt;?=$randomImage;?&gt;" alt="&lt;?=$randomImage;?&gt;" /&gt;
     }
  </code></pre>
  
  <p>But I am still stuck with this code. Anyone please help to improve this code? or any other idea?</p>
  
  <p>Thanks.</p>