What function in PHP is used to delete directories and can it also delete directories with files in them?

To delete directories in PHP, you can use the `rmdir()` function. This function can delete empty directories, but if you want to delete directories with files in them, you need to first remove all the files within the directory before deleting it. You can achieve this by using a combination of functions like `scandir()`, `unlink()`, and `rmdir()`.

function deleteDirectory($dir) {
    if (!file_exists($dir)) {
        return false;
    }
    
    $files = array_diff(scandir($dir), array('.', '..'));
    foreach ($files as $file) {
        (is_dir("$dir/$file")) ? deleteDirectory("$dir/$file") : unlink("$dir/$file");
    }
    
    return rmdir($dir);
}

// Example usage
$directory = 'path/to/directory';
deleteDirectory($directory);