How can Apache's ErrorHandler be utilized in conjunction with PHP to manage and respond to HTTP status codes?

When using Apache's ErrorHandler directive in conjunction with PHP, you can set up custom error pages for specific HTTP status codes. This allows you to provide more user-friendly error messages or redirect users to relevant pages based on the status code received.

<?php
// Set up custom error handling for specific HTTP status codes
if ($_SERVER['REDIRECT_STATUS'] == 404) {
    include('404_error_page.php');
} elseif ($_SERVER['REDIRECT_STATUS'] == 500) {
    include('500_error_page.php');
} else {
    include('generic_error_page.php');
}
?>