What is the purpose of using preg_match_all in PHP?

When working with PHP, the preg_match_all function is used to perform a global regular expression match on a string. This function allows you to find all occurrences of a pattern within a given string, rather than just the first occurrence. This can be useful when you need to extract multiple pieces of information from a string that follow a specific pattern.

<?php
$string = "The quick brown fox jumps over the lazy dog";
$pattern = '/\b\w{4}\b/'; // Match 4-letter words

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

print_r($matches[0]);
?>