The rmdir()
function in PHP removes an empty directory.
rmdir(string $path, resource $context = ?): bool
path
: This specifies the path of the directory we want to remove.
context
: This is an optional parameter that specifies the context of the file handle. It is a set of options that modify the system’s behavior.
rmdir()
returns true
if the directory is removed successfully. Otherwise, in case of any error, it returns false
.
The following code shows how to use the rmdir()
function.
<?phpmkdir("documents");if(rmdir("documents")){echo ("Directory removed");}?>
In the code above, a directory named documents
is created. It is then removed successfully using the rmdir
function since it is an empty directory.
Free Resources