What are the best practices for displaying error messages in PHP scripts to aid in troubleshooting?

When displaying error messages in PHP scripts, it is important to provide clear and specific messages to aid in troubleshooting. Avoid displaying sensitive information that could compromise security, and instead focus on providing helpful information for debugging purposes. Utilize PHP's error handling functions, such as error_reporting() and ini_set(), to control how errors are displayed.

// Set error reporting level to display all errors except notices
error_reporting(E_ALL & ~E_NOTICE);

// Display errors on the screen for debugging purposes
ini_set('display_errors', 1);