- Output for 5.6.13, 8.1.23 - 8.1.33, 8.2.10 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- Array ( [0] => /article/42-is-the-answer [id] => 42 [1] => 42 [slug] => is-the-answer [2] => is-the-answer ) Array ( [id] => 42 [slug] => is-the-answer )
<?php
// example code
$pattern = "#^/article/(?<id>\d+)-(?<slug>.+)$#";
$url = "/article/42-is-the-answer";
preg_match($pattern, $url, $args);
print_r($args);
$args = array_filter($args, 'is_string', ARRAY_FILTER_USE_KEY);
print_r($args);