How can one properly access and display the output of preg_match_all in PHP?

When using preg_match_all in PHP, the function returns the number of full pattern matches found, and the matches themselves are stored in the $matches parameter as an array. To properly access and display the output of preg_match_all, you need to loop through the $matches array to extract and display the matched patterns.

// Example code to properly access and display the output of preg_match_all
$string = "Hello, World! This is a test string.";
$pattern = '/\b\w+\b/';

if (preg_match_all($pattern, $string, $matches)) {
    foreach ($matches[0] as $match) {
        echo $match . "<br>";
    }
}