I have an array containing all routes/urls and their path,
Example : $route = array(
'/' => 'files/index.php',
'pages' => 'files/pages.php',
'pages/add' => 'files/page-add.php',
'posts/*' => 'files/posts.php',
)
Using array_key_exists() i check if a route exists in the array and if yes then load its path and it works if a direct match is found.
I want it to match to posts/* path whenever a request is made to posts/anything, posts/view/10, And i cannot do this using array_key_exists().
Do you guys have any ideas/suggestions on which method i should use?
Do a combination of two strategies:
preg_match()function. This gives you endless possibilities to describe patterns, though it obviously is slower than looking for direct matches.