How can an autoloader in PHP help manage the inclusion of classes and functions in a more efficient way?

When working on larger PHP projects with many classes and functions, managing the inclusion of all these files can become cumbersome and error-prone. By using an autoloader in PHP, you can automate the process of including classes and functions only when they are needed, improving efficiency and reducing the likelihood of errors.

// Autoloader function to automatically include classes and functions
spl_autoload_register(function ($class) {
    include 'path/to/classes/' . $class . '.php';
});

// Usage example
$obj = new MyClass();