What are the best practices for organizing PHP files and including them within a website layout to ensure proper functionality?

To organize PHP files within a website layout, it is best practice to create separate directories for different types of files such as controllers, models, views, and libraries. Use an autoloader to automatically include classes when needed. To ensure proper functionality, include files using relative paths to avoid issues with file paths when moving the website to a different server.

// Autoloader function to include classes
function autoloader($class) {
    $class = str_replace('\\', '/', $class);
    require_once __DIR__ . '/classes/' . $class . '.php';
}

spl_autoload_register('autoloader');