Skip to content

Instantly share code, notes, and snippets.

@toledorobia
Last active January 5, 2018 15:11
Show Gist options
  • Save toledorobia/0308c77c961cc6d48b3d to your computer and use it in GitHub Desktop.
Save toledorobia/0308c77c961cc6d48b3d to your computer and use it in GitHub Desktop.
PHP - Delete dirs recursively
<?php
function rmdir_recursive($dir) {
foreach(scandir($dir) as $file) {
if ('.' === $file || '..' === $file) continue;
if (is_dir("$dir/$file")) rmdir_recursive("$dir/$file");
else unlink("$dir/$file");
}
rmdir($dir);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment