What is the purpose of using preg_match in a for-loop for a search function in PHP?

When using preg_match in a for-loop for a search function in PHP, the purpose is to iterate through an array of strings and check each string against a regular expression pattern to find matches. This allows for a more dynamic and customizable search functionality compared to simple string comparisons.

$search_query = '/pattern/';
$strings = ['string1', 'string2', 'string3'];

foreach ($strings as $string) {
    if (preg_match($search_query, $string)) {
        echo "Match found in: $string\n";
    }
}