You use anonymous functions, also known as closures, which allow you to create functions that do not have specific names.
Closures can also inherit variables from the parent scope. Any such variable must be declared in the use construction. Changes inside will not be reflected on a variable from the parent scope, in order to change the variable inside and reflect changes to the parent area you must add before the start of &, then the variable will be passed by reference.
$foo = function ($sep) use (&$str) { $out = $sep . $str . $sep; return $out; };
The global $ a construction says that the $ a variable is global, that is, it is synonymous with global $ a and changes within the function will be reflected in the global scope. After defining variables through global, all references to any of these variables will point to their global version.
Thus, the global instruction creates a reference to the $ GLOBALS array, so these two entries will be equivalent:
function test() { global $a; $а = 10; } function test() { $а = &$GLOBALS['a']; $а = 10; }
The $ GLOBALS array is accessible from anywhere in the program — including from the function body — and it does not need to be additionally declared.
For your question, I can say that you define functions in two ways is exactly the same. You simply change the way parameters are passed to the function.
PS Excessive definition of global variables threatens to complicate the search for errors in the program. This is the real way to drive the craziness of the programmer, who will then disassemble your program.