Can $ matches be an associative array?
|
2 answers
It can be mixed. Here is an example:
<?php $str = '2016-10-06'; if (preg_match('%^(?P<year>\d+)-(?P<month>\d+)-(?P<day>\d+)$%', $str, $matches)) { var_dump($matches); } Result:
array (size=7) 0 => string '2016-10-06' (length=10) 'year' => string '2016' (length=4) 1 => string '2016' (length=4) 'month' => string '10' (length=2) 2 => string '10' (length=2) 'day' => string '06' (length=2) 3 => string '06' (length=2) - Yes, I also read about it, thanks! - Timur Musharapov
|
Not. The $matches array contains all occurrences of the found substrings. And the index in the array is the index of the substring in the regular expression
|