What function in PHP can be used to handle errors and add custom messages to error outputs?

To handle errors and add custom messages to error outputs in PHP, you can use the `set_error_handler()` function. This function allows you to define a custom error handling function that will be called when an error occurs in your PHP script. You can use this custom error handling function to log errors, display custom error messages, or perform any other desired action when an error occurs.

function customErrorHandler($errno, $errstr, $errfile, $errline) {
    // Log the error or display a custom error message
    echo "An error occurred: $errstr";
}

// Set the custom error handler
set_error_handler("customErrorHandler");

// Trigger an error for testing
$undefinedVariable = $nonExistentArray['key'];