I have an array of strings:
$routes = Array
(
[0] => Array
(
[0] => /
)
[1] => Array
(
[0] => /articles/[:slug]?
)
[2] => Array
(
[0] => /articles/[:cid]/[:slug]?
)
[3] => Array
(
[0] => /articles/[a:year]/?[*:month]?/?[*:day]?
)
)
And a data array with params below. Based on this data I want to find best match from routes.
Array
(
[year] => 2012
[day] => 11
[month] => 01
)
In the example above: I want to get $routes[3].
I have tried something like this:
foreach($routes as $route) {
if (preg_match_all('`(/|\.|)\[([^:\]]*+)(?::([^:\]]*+))?\](\?|)`', $route[0], $matches, PREG_SET_ORDER)) {
foreach($matches as $match) {
list($block, $pre, $type, $param, $optional) = $match;
// How to check???
}
}
}