<?php
/**
* @param $path
* @param $extension
*
* @return array
*/
function getFilesInPathWithExtension($path, $extension)
{
$directoryIterator = new RecursiveDirectoryIterator($path);
$recursiveIterator = new RecursiveIteratorIterator($directoryIterator);
$files = [];
foreach ($recursiveIterator as $item) {
if ($item->isFile() and $item->getExtension() === $extension) {
$files[] = $item;
}
if ($item->isDir() and $item->getFilename() !== "." and $item->getFilename() !== "..") {
$files = array_merge(
$files, getFilesInPathWithExtension($item->getPathName(), $extension)
);
}
}
return $files;
}