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 (e.g. array("someFunc"=>&x(), "anotherFunc"=>$this->anotherFunc())). Thanks!
Take the 2-minute tour
×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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.
|
|||||||||||||||||||||
|
check out PHP's 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. |
|||||
|
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. |
|||||||||||||||||
|