This is a discussion on How to pass a function to a function?, and how to pass the variables of the function? within the alt.comp.lang.php forums, part of the PHP Programming Forums category; I'd like to write a function like: function f(){ ... bla ...} f_example(f); function f_example($function_to_execute) {...bla... $function_to_execute() ...bla....} AND ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'd like to write a function like:
function f(){ ... bla ...} f_example(f); function f_example($function_to_execute) {...bla... $function_to_execute() ...bla....} AND how to pass the variable of the function : function f_example($function_to_execute($var1,$var2)) {...bla... $function_to_execute() ...bla....} Thank you in advance for the time you'll spend for me, Andrea. |
|
|||
|
"_andrea.l" <andrea.lorizANTISPAM@libero.it> wrote in message
news:q3NYe.16114$Jr.257637@twister2.libero.it... > I'd like to write a function like: > > function f(){ ... bla ...} > f_example(f); > > function f_example($function_to_execute) > {...bla... $function_to_execute() ...bla....} > > AND how to pass the variable of the function : > > function f_example($function_to_execute($var1,$var2)) > {...bla... $function_to_execute() ...bla....} > > Thank you in advance for the time you'll spend for me, Actually just like that. :) Example: <?php function f_example($function_to_execute, $param){ // Let's first check function exists before calling it. if(function_exists($function_to_execute)) $function_to_execute($param); } $myfunction = "print"; f_example($myfunction, "Hello World"); // This runs the function print and gives // "Hello World" to it as a parameter, // so it prints Hello World. ?> There is also a function for this, it's called call_user_func(), you might want to try that, but it's much more simple to just stick the function name into a variable and call the function with the variable... -- Welcome to Usenet! Please leave tolerance, understanding and intelligence at the door. They aren't welcome here. antaatulla.sikanautaa@gmail.com.NOSPAM.invalid |