a simple snipped for removing empty dirs recursive :
<?php
function removeEmptyDirs($fullPath)
{
if(!is_dir($fullPath)){
return;
}
$children = array_diff(scandir($fullPath), ['.','..']);
foreach($children as $child){
removeEmptyDirs($fullPath. $child. DIRECTORY_SEPARATOR);
}
$children = array_diff(scandir($fullPath), ['.','..']);
if(empty($children)){
echo "the $fullPath empty directory has been removed.\n";
rmdir($fullPath);
}
}
?>