How can the dirname() function be used to manipulate directory paths in PHP?

The dirname() function in PHP can be used to extract the directory component of a given path. This can be useful for manipulating directory paths, such as getting the parent directory or removing the file name from a path. By using dirname(), you can easily work with directory paths in PHP.

// Example of using the dirname() function to manipulate directory paths
$path = "/var/www/html/index.php";
$directory = dirname($path);

echo "Original path: " . $path . "\n";
echo "Directory component: " . $directory;