What function is used to read the contents of a directory in PHP?

To read the contents of a directory in PHP, you can use the `scandir()` function. This function returns an array of files and directories in the specified directory. You can then iterate over this array to access the names of the files and directories within the directory.

$directory = "/path/to/directory";

$contents = scandir($directory);

foreach ($contents as $item) {
    echo $item . "<br>";
}