What is the preferred form for references in the $replacement parameter of preg_replace in PHP?

When using the preg_replace function in PHP, it is preferred to use the $replacement parameter as a callback function rather than a simple string. This allows for more flexibility and customization in the replacement process. By using a callback function, you can dynamically generate the replacement string based on the matched pattern.

// Using a callback function in preg_replace for more flexibility in replacements
$string = "Hello, world!";
$pattern = "/world/";
$replacement = function($match) {
    return strtoupper($match[0]);
};

$result = preg_replace_callback($pattern, $replacement, $string);

echo $result; // Output: Hello, WORLD!