get('/', function ($request, $response) { return $response->write('Homepage'); }); $app->get('/about', function ($request, $response) { return $response->write('About Us'); }); $app->run(); ?>
respond('GET', '/', function ($request, $response) { return $response->body('Homepage'); }); $router->respond('GET', '/about', function ($request, $response) { return $response->body('About Us'); }); $router->dispatch(); ?>In this example, we are using the Klein PHP Router library. We have defined the same two routes as in the previous example. When a user visits the homepage or the about page, the functions associated with those routes will be executed and the corresponding string will be returned. In conclusion, PHP Router is a package library used for defining routes in PHP web applications. It helps in creating clean and organized code and has many options regarding routing. Slim and Klein are some examples of the package library used for routing in PHP.