What best practices should be followed when passing multiple parameters to a callback function in PHP, especially when using regular expressions?

When passing multiple parameters to a callback function in PHP, especially when using regular expressions, it is best practice to use an anonymous function or create a custom function that accepts all the required parameters. This ensures that the callback function has access to all the necessary data without relying on global variables or other external factors.

// Example of passing multiple parameters to a callback function using an anonymous function
$pattern = '/\d+/';
$string = '12345';

preg_replace_callback($pattern, function($matches) use ($string) {
    // Access $string within the callback function
    echo "Match found in $string: " . $matches[0] . "\n";
}, $string);