How can PHP developers efficiently replace multiple instances of specific values in HTML tags using preg_replace and arrays, while avoiding delimiter errors and maintaining proper syntax?

When using preg_replace to replace multiple instances of specific values in HTML tags, it's important to use proper delimiters to avoid syntax errors. One efficient way to do this is by using arrays to store the search and replace values, then looping through the array to perform the replacements. By properly escaping special characters and maintaining the correct syntax, developers can ensure that the replacements are done accurately within the HTML tags.

$html = '<div class="old">Old Value</div><span class="old">Another Old Value</span>';

$search = array('/class="old"/', '/Old Value/', '/Another Old Value/');
$replace = array('class="new"', 'New Value', 'Another New Value');

$new_html = preg_replace($search, $replace, $html);

echo $new_html;