$file_extensions * * @return array */ public function getFilesInDir($dir_path, array $file_extensions) { $file_paths = []; /** @var \RecursiveDirectoryIterator */ $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($dir_path)); $iterator->rewind(); while ($iterator->valid()) { if (!$iterator->isDot()) { $extension = $iterator->getExtension(); if (in_array($extension, $file_extensions, true)) { $file_paths[] = (string)$iterator->getRealPath(); } } $iterator->next(); } return $file_paths; } }