How can foreach loops be utilized to improve the output of regex pattern matches in PHP?
When using regex pattern matches in PHP, the matches are typically returned as an array. To improve the output of these matches, you can utilize a foreach loop to iterate over the array and display each match individually. This allows for more control over how the matches are presented or processed.
$string = "Hello, my email is example@email.com and my phone number is 123-456-7890.";
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match_all($pattern, $string, $matches);
foreach($matches[0] as $match) {
echo $match . "<br>";
}