Skip to content

Instantly share code, notes, and snippets.

@saltybeagle
Created January 29, 2010 16:32
Show Gist options
  • Save saltybeagle/289865 to your computer and use it in GitHub Desktop.
Save saltybeagle/289865 to your computer and use it in GitHub Desktop.
PHP recursive delete with closure
<?php
// recursive delete function
$unlink = function($path) use (&$unlink) {
if (is_file($path)){
return unlink($path);
}
if (is_dir($path)) {
$files = glob(rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*');
foreach($files as $file){
$unlink($file);
}
return rmdir($path);
}
};
$unlink('/Thedir');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment