PHP: Delete directory recursively

Published:
function delete_directory($dir)
{
    if( ! file_exists($dir))
        return;

    $it = new RecursiveDirectoryIterator($dir);
    $it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);

    foreach($it as $file)
        if($file->isDir())
            @rmdir($file->getRealPath());
        else
            @unlink($file->getRealPath());
}