PHP code example of diego03 / router

1. Go to this page and download the library: Download diego03/router library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

diego03 / router example snippets




iego03\Router\Router;

$router = new Router();

$router->get('/', function () {
    return [
        'message' => 'Hello World!'
    ];
});

$router->get('/users/:id', function ($id) {
    return [
        'id' => $id
    ];
});

$route = $router->match(
    $_SERVER['REQUEST_METHOD'],
    $_SERVER['REQUEST_URI']
);

echo json_encode(
    $route['handler'](
        ...$route['params']
    )
);