How can the realpath() function be used to troubleshoot file path issues in PHP?

When working with file paths in PHP, issues can arise due to incorrect or relative paths. The realpath() function can be used to resolve these issues by returning the canonicalized absolute pathname. This can help in troubleshooting file path problems and ensuring that the correct path is being used.

// Example of using realpath() to troubleshoot file path issues
$file = 'example.txt';
$fullPath = realpath($file);

if ($fullPath) {
    echo "The full path to $file is: $fullPath";
} else {
    echo "File not found or path is incorrect.";
}