Note that if a parenthesed group is not matched, its key may or may not be present in $matches. For instance,
<?php preg_match('/(foo)?(bar)?(baz)?/', 'bar', $matches);
print_r($matches);
// outputs
// Array
// (
// [0] => bar
// [1] =>
// [2] => bar
// )
?>
Note that there is no element with key '3' in $matches, but an element with key '1' (the empty string). This inconsistent behavior also applies to named groups.