Do a scandir and count the contents. An empty directory always contains . and ... So if the count is greater than 2 it is not empty.
function isDirectoryEmpty(string $dir): bool
{
ifreturn (is_dir($dir)) {
return&& count(scandir($dir)) <= 2;
}
return false;
}