title: Which is better to read files from a directory using PHP - glob() or scandir() or readdir()?
body: <p>I am a beginner in PHP. I would like to read files from a specific folder / directory. I don't want sub-folders or files in them. I just want to list out direct files inside the directory. I ended up with 3 solutions, <code>glob()</code> , <code>readdir()</code> , and <code>scandir()</code>. I can do file listing like;</p>
  
  <pre><code>foreach (glob("*.*") as $filename) {
      echo $filename."&lt;br /&gt;";
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if (is_dir($dir)) {
      if ($dh = opendir($dir)) {
          while (($file = readdir($dh)) !== false) {
              echo "filename: .".$file."&lt;br /&gt;";
          }
          closedir($dh);
      }
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>$files = scandir($dir);
  foreach($files as $val){
    echo $val;
  }
  </code></pre>
  
  <p>Which one is faster and more efficient?</p>