What is the advantage of using closures over arrays in the context of preg_replace_callback in PHP?

When using preg_replace_callback in PHP, closures offer the advantage of encapsulating the callback function within a single entity, making the code cleaner and more organized compared to using arrays. Closures also provide a more concise and readable way to define the callback function without the need to create a separate named function.

// Using closures with preg_replace_callback
$text = "Hello, world!";
$replaced_text = preg_replace_callback('/\b\w{5,}\b/', function($matches) {
    return strtoupper($matches[0]);
}, $text);

echo $replaced_text;