map('GET', '/', function (ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write('Hello world!'); return $response; }); $router->dispatch($request);
map('GET', '/user/{user_id}', function (ServerRequestInterface $request, ResponseInterface $response, array $args) { $response->getBody()->write('User ID: ' . $args['user_id']); return $response; }); $router->dispatch($request);
group('/admin', function (RouteCollection $router) { $router->map('GET', '/', function (ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write('Admin Homepage'); return $response; }); $router->map('GET', '/users', function (ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write('All Users page'); return $response; }); }); $router->dispatch($request);In summary, PHP Router is a package library used to define endpoints and Routing rules that allow users to navigate to different pages of your website or to trigger specific actions. The examples above demonstrate the basic concepts of this package and how it can be used for different types of web applications.