How can the error of needing a string as the second parameter be resolved when using preg_match_all in PHP?

When using preg_match_all in PHP, the error of needing a string as the second parameter can be resolved by passing the subject string as the first parameter and an empty array as the second parameter. This will allow the function to store the matched results in the empty array.

$subject = "Hello, this is a test string";
$pattern = '/\b\w+\b/';
$matches = array();

preg_match_all($pattern, $subject, $matches);

print_r($matches[0]);