In PHP, how can backreferences be used effectively with preg_replace to simplify string manipulation tasks?

Backreferences in PHP can be used effectively with preg_replace to simplify string manipulation tasks by allowing you to refer to captured groups in the regular expression pattern within the replacement string. This can be useful for tasks like swapping the order of words in a string, formatting dates, or reordering elements in a list.

$string = "Hello, World!";
$newString = preg_replace('/(Hello), (World)/', '$2 $1', $string);
echo $newString; // Output: World Hello