How can the use of foreach loops improve the efficiency and readability of PHP code when working with regex functions like preg_replace?

When working with regex functions like preg_replace in PHP, using foreach loops can improve efficiency and readability by allowing you to apply the regex pattern to multiple elements in an array without having to repeat the code for each element. This can make your code more concise and easier to maintain.

// Example code snippet using foreach loop with preg_replace
$strings = array("Hello, World!", "This is a test", "12345");

$pattern = '/[0-9]/'; // regex pattern to match numbers

foreach ($strings as $string) {
    $result = preg_replace($pattern, '', $string);
    echo $result . "\n";
}