How can PHP error logging be utilized effectively to troubleshoot issues in a PHP script?

To effectively troubleshoot issues in a PHP script, PHP error logging can be utilized by setting up a log file to capture errors, warnings, and notices generated by the script. This allows developers to easily identify and address any issues that may arise during script execution.

// Enable error logging
ini_set('log_errors', 1);
ini_set('error_log', '/path/to/error.log');

// Trigger an error to test logging
trigger_error('This is an error message', E_USER_ERROR);