Created
November 26, 2020 13:47
-
-
Save onliniak/b727ff80b2adc0a877e04c43722a7c42 to your computer and use it in GitHub Desktop.
Naive PHP Router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| function createRoutes(){ | |
| $routes = array(); | |
| array_push($routes, ['hello' => hello()]); | |
| array_push($routes, ['hello123' => hello123()]); | |
| return $routes; | |
| } | |
| function hello(){ | |
| return 'Hello World !'; | |
| } | |
| function hello123(){ | |
| return 'I am not'; | |
| } | |
| $start = array_column(createRoutes(), 'hello'); | |
| print_r($start); # => Array | |
| # ( | |
| # [0] => Hello World ! | |
| # ) | |
| ?> |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The only advantage I know of this solution is much cleaner code, compared to many GETs.
With fewer functions the performance is not too much reduced.