![]() |
| |||||||
| PHP Forum PHP Forum. PHP Programming questions and answers here. |
![]() |
| | LinkBack | Thread Tools | Search this Thread | Display Modes |
| |||
| How to pass a function to a function?, and how to pass the variables of the function?
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. |
| |||
| How to pass a function to a function?, and how to pass the variables of the function?
"_andrea.l" <andrea.lorizANTISPAM@libero.it> wrote in message news:q3NYe.16114$Jr.257637@twister2.libero.it... 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 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| trying to pass by reference to an optional function parameter | John T | PHP Forum | 3 | 06-12-2005 11:51 PM |
| Creating variables that a function can see | Brian | PHP Forum | 2 | 04-20-2004 02:49 AM |
| PHP - function | Pawel | PHP Forum | 4 | 02-24-2004 08:12 PM |
| Postfields in WML does not pass all variables to next WML page | uitbundig | PHP Forum | 0 | 01-30-2004 08:10 PM |
| Postfields in WML does not pass all variables to next WML page | uitbundig | PHP Forum | 0 | 01-30-2004 08:10 PM |