What is the purpose of an autoloader in PHP?
The purpose of an autoloader in PHP is to automatically load classes without the need to manually include them using require or include statements. This helps in organizing and managing class files more efficiently, especially in larger projects where there are many classes to be loaded.
// Autoloader function to automatically load classes
spl_autoload_register(function ($class) {
include 'classes/' . $class . '.php';
});
// Example usage of autoloader
$obj = new MyClass();