I need to be able to call a function, but the function name is stored in a variable, is this possible? e.g:
function foo () { //code here } function bar () { //code here } $functionName = "foo"; // i need to call the function based on what is $functionName
Anyhelp would be great.
Thanks!
Following code can help to write dynamic function in PHP. now the function name can be dynamically change by variable '$current_page'.
Complementing the answer of @Chris K if you want to call an object's method, you can call it using a single variable with the help of a closure:
I posted another example here