title: Return total number of files within a folder using PHP
body: <p>Is there a better/simpler way to find the number of images in a directory and output them to a variable?</p>
  
  <pre><code>function dirCount($dir) {
    $x = 0;
    while (($file = readdir($dir)) !== false) {
      if (isImage($file)) {$x = $x + 1}
    }
    return $x;
  }
  </code></pre>
  
  <p>This seems like such a long way of doing this, is there no simpler way?</p>
  
  <p><strong>Note:</strong> The isImage() function returns true if the file is an image.</p>