What is the issue with using preg_match_all in PHP in the context described in the forum thread?

The issue with using preg_match_all in the context described in the forum thread is that it returns an array of matches including both the full pattern matches and the subpattern matches. To only retrieve the subpattern matches, you can use the PREG_SET_ORDER flag in conjunction with preg_match_all. This flag organizes the matches in a multi-dimensional array where each element contains the subpattern matches.

// Example code snippet to retrieve only subpattern matches using preg_match_all with PREG_SET_ORDER flag

$string = "Hello, my email is john@example.com and my friend's email is jane@example.com";

$pattern = '/(\w+@\w+\.\w+)/';

preg_match_all($pattern, $string, $matches, PREG_SET_ORDER);

foreach ($matches as $match) {
    echo $match[1] . "\n";
}