PHP Remove or Delete Directory RecursivelyRecursively delete all files and folders from a given path and can be used anywhere you wish to delete directory recursively.

It is often a requirement for a PHP script to delete files recursively or delete directory recursively, either as a clean-up operation for cached files or to remove unwanted files.
This function will allow your PHP script to delete directories and files recursively. Simply call the function passing in the path of the directory to recursively delete.
Care should be taken when deleting recursively as it can be easy to accidentally delete files with no way to recover them.
Delete Directory Recursively
/**
* Delete a file or recursively delete a directory
*
* @param string $str Path to file or directory
*/
function recursiveDelete($str){
if(is_file($str)){
return @unlink($str);
}
elseif(is_dir($str)){
$scan = glob(rtrim($str,'/').'/*');
foreach($scan as $index=>$path){
recursiveDelete($path);
}
return @rmdir($str);
}
}