How does the order of parameter evaluation in PHP functions like preg_replace affect backreference usage?

When using backreferences in PHP functions like preg_replace, the order of parameter evaluation is important. If the replacement string contains backreferences (e.g., $1, $2), make sure to use single quotes for the string to prevent PHP from interpreting them as variables before passing them to the function. This ensures that the backreferences are correctly evaluated by the preg_replace function.

$string = 'Hello, world!';
$pattern = '/(Hello), (world)/';
$replacement = '$2, $1';
$new_string = preg_replace($pattern, '$replacement', $string);
echo $new_string; // Output: world, Hello