What is a closure in PHP and why is the use operator needed?
Hello everyone! I started learning PHP and came across the topic of anonymous functions and closures. I think I figured out anonymous functions, but when I got to closures, I stumbled on the `use` operator.
Here's the code I saw in the documentation:
```php
$message = "Hello, world!";
$greeting = function() use ($message) {
echo $message;
};
$greeting();
```
I understand that this works, but I don't understand why this `use` is needed. Why can't I just access the `$message` variable inside the function, like in regular functions? For example:
```php
function test() {
echo $message; // Why doesn't this work?
}
```
I also read that closures can "capture" variables from the outer scope. What does that mean? And why use closures at all if you can just pass a variable