diff --git a/README.md b/README.md index f055880..ad82659 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,25 @@ Route::run('/api/v1'); Do not forget to edit the basepath in .htaccess too if you are on Apache2. +## Use return instead of echo +You don't have to use `echo` to output your content. You can also use the `return` statement. Everything that gets returned is echoed automatically. + +```php +// Add your first route +Route::add('/', function() { + return 'Welcome :-)'; +}); +``` + +## Use arrow functions +Since PHP 7.4 you can also use arrow functions to output your content. So you can easily use variables from outside and you can write shorter code. +Please be aware that an Arrow function must always return a value. Therefore you cannot use `echo` here. +You can find an example in index.php. However, this is deactivated, as it only works from PHP 7.4. + +```php +Route::add('/arrow/([a-z-0-9-]*)', fn($foo) => 'This is a working arrow function example. Parameter: '.$foo ); +``` + ## Enable case sensitive routes, trailing slashes and multi match mode The second, third and fourth parameters of `Route::run('/', false, false, false);` are set to false by default. Using this parameters you can switch on and off several options: diff --git a/index.php b/index.php index f1b35bd..7ff5288 100644 --- a/index.php +++ b/index.php @@ -29,6 +29,7 @@ function navi() {
  • PHP Info
  • Non english route: german
  • Non english route: arabic
  • +
  • Arrow function test (please enable this route first)
  • aTrailingSlashDoesNotMatter
  • aTrailingSlashDoesNotMatter/
  • theCaseDoesNotMatter
  • @@ -143,7 +144,8 @@ Route::add('/return', function() { // Arrow function example // Note: You can use this example only if you are on PHP 7.4 or higher -// Route::add('/arrow/([a-z-0-9-]*)', fn($foo) => 'This is a working arrow function example. Parameter: '.$foo ); +// $bar = 'bar'; +// Route::add('/arrow/([a-z-0-9-]*)', fn($foo) => navi().'This is a working arrow function example.
    Parameter: '.$foo. '
    Variable from global scope: '.$bar ); // Trailing slash example Route::add('/aTrailingSlashDoesNotMatter', function() {