What is the purpose of using is_dir() function in PHP?

The is_dir() function in PHP is used to check if a given path is a directory. This function can be helpful when you need to verify if a specific path points to a directory or not before performing any operations on it. By using is_dir(), you can ensure that your code handles directories correctly and avoids errors when dealing with file systems.

$path = '/path/to/directory';

if (is_dir($path)) {
    echo "The path is a directory.";
} else {
    echo "The path is not a directory.";
}