How can the $matches array from preg_match_all be effectively utilized to retrieve the desired value from a PHP string?
When using preg_match_all in PHP to extract specific values from a string, the $matches array contains the captured values. To retrieve the desired value, you can access it by specifying the appropriate index in the $matches array. For example, if you want to retrieve the first captured value, you can access it using $matches[0][0].
$string = "Hello, my email is test@example.com";
$pattern = '/([a-zA-Z0-9._%+-]+)@([a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})/';
preg_match_all($pattern, $string, $matches);
$email = $matches[0][0];
echo $email; // Output: test@example.com