What is the purpose of using preg_match_all() in PHP and what are its parameters?

The purpose of using preg_match_all() in PHP is to perform a global regular expression match on a string and return all matches. This function is useful when you want to find multiple occurrences of a pattern within a string. The parameters for preg_match_all() include the regular expression pattern to match, the string to search within, and an optional parameter to store the matches found.

// Example of using preg_match_all() to find all occurrences of a pattern in a string
$string = "The quick brown fox jumps over the lazy dog";
$pattern = '/\b\w{4}\b/'; // Match words that are exactly 4 characters long

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

print_r($matches[0]); // Output all matches found