How can regular expressions be effectively used in PHP to manipulate string values within an array?

Regular expressions can be effectively used in PHP to manipulate string values within an array by iterating through each element of the array and applying the regular expression pattern to each string value. This allows for searching, replacing, or extracting specific patterns from the strings in the array.

<?php
// Sample array with string values
$array = ["apple123", "banana456", "cherry789"];

// Iterate through each element of the array
foreach ($array as &$value) {
    // Use preg_replace to remove all numbers from the string
    $value = preg_replace('/[0-9]/', '', $value);
}

// Output the modified array
print_r($array);
?>