title: Include php file randomly
body: <p>I have a question about php include. Here goes the existing code that i have.</p>
  
  <pre><code>&lt;?php
  srand();
  $files = array("folder/content1.php", "folder/content2.php", "folder/content3.php", "folder/content4.php");
  $rand = array_rand($files);
  include ($files[$rand]);
  ?&gt;
  </code></pre>
  
  <p>This code actually works very well for me now as the content displaying randomly. But, i would like to get something better. Because, by using this code, everytime i have added a new content like <code>content5.php</code>, <code>content6.php</code> and so on, i have to bother to update the code above to make new <code>content.php</code> appear. </p>
  
  <p>Is there any solution i can have, to not to bother the code above everytime i add a new <code>content.php</code> and the new <code>content.php</code> appears automatically when added? Is it possible?</p>
  
  <p>Updated: New testing code(tested failed again with part of my page mising)</p>
  
  <pre><code>    &lt;?php
  $sDirectory     = 'myfolder';
  if( is_dir( $sDirectory ) ) 
  {
      $rDir = opendir( $sDirectory );
      while( ( $sFile = readdir( $rDir ) ) !== FALSE ) 
      {
          if( ( $sFile == '.' ) || ( $sFile === '..' ) )
          {
              continue;
          }
          $aFiles[] = $sDirectory . '/' . $sFile;
      }
  }
  $sRandom = array_rand( $aFiles );
  require_once( $aFiles[ $sRandom ] );
  ?&gt;
  </code></pre>