How can PHP be used to rename directories?

To rename directories using PHP, you can use the `rename()` function. This function takes two parameters: the current directory name and the new directory name. Make sure the current directory exists and the new directory name is unique to avoid conflicts.

$oldDir = 'old_directory';
$newDir = 'new_directory';

if (file_exists($oldDir)) {
    if (rename($oldDir, $newDir)) {
        echo 'Directory renamed successfully.';
    } else {
        echo 'Error renaming directory.';
    }
} else {
    echo 'Directory does not exist.';
}