// define product categories $categories = array('books', 'electronics', 'clothing'); // get category parameter $category = Router::getParams('category'); // check if category parameter is valid if (in_array($category, $categories)) { // display products based on category displayProducts($category); } else { // display error message echo 'Invalid category parameter'; }
// get post ID parameter $postId = Router::getParams('postId'); // retrieve blog post data from database $post = getBlogPost($postId); // display blog post content displayBlogPost($post);The package library that the getParams method is in may vary depending on which PHP Router library is being used. Some popular PHP Router libraries include FastRoute, Klein, and AltoRouter.