// Initialize the router $router = new Router(); // Define the route $router->get('/user/{id}', function ($id) { // Use the ID to retrieve the user }); // Get the user ID parameter from the URL $id = $router->getParam('id');
// Initialize the router $router = new Router(); // Define the route $router->get('/user/{userId}/book/{bookId}', function ($userId, $bookId) { // Use the IDs to retrieve the user and book }); // Get the user ID and book ID parameters from the URL $userId = $router->getParam('userId'); $bookId = $router->getParam('bookId');This code defines a route that matches URLs like /user/123/book/456. The getParam method is called twice, once for each parameter. Package library: This feature is part of most PHP router libraries, including FastRoute and Aura.Router.