I can't seem to find anything of this, and was wondering if it's possible to store a function or function reference as a value for an array element. For e.g.
array("someFunc" => &x(), "anotherFunc" => $this->anotherFunc())
Thanks!
I can't seem to find anything of this, and was wondering if it's possible to store a function or function reference as a value for an array element. For e.g.
array("someFunc" => &x(), "anotherFunc" => $this->anotherFunc())
Thanks!
check out PHP's
call_user_func
. consider the below example.consider two functions
now if you want to execute all the function in a sequence you can do it with a loop.
plus array can hold any data type, be it function call, nested arrays, object, string, integer etc. etc.
PHP supports the concept of variable functions, so you can do something like this:
Yout can check more examples in manual.
You can "reference" any function. A function reference is not a reference in the sense of "address in memory" or something. It's merely the name of the function.
Yes, you can:
This does, of course, require PHP anonymous function support, which arrived with PHP version 5.3.0. This is going to leave you with quite unreadable code though.