Skip to content

Instantly share code, notes, and snippets.

@onliniak
Created November 26, 2020 13:47
Show Gist options
  • Select an option

  • Save onliniak/b727ff80b2adc0a877e04c43722a7c42 to your computer and use it in GitHub Desktop.

Select an option

Save onliniak/b727ff80b2adc0a877e04c43722a7c42 to your computer and use it in GitHub Desktop.
Naive PHP Router
<?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 !
# )
?>
@onliniak
Copy link
Copy Markdown
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment