Computer Forum  

Go Back   Computer Forum > Computer Forums > Programming Forum > PHP Forum

PHP Forum PHP Forum. PHP Programming questions and answers here.


How to pass a function to a function?, and how to pass the variables of the function?

PHP Forum

PHP Forum. PHP Programming questions and answers here.


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-23-2005, 06:14 AM
_andrea.l
Guest
 
Posts: n/a
_andrea.l RSS Feed
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.


Reply With Quote
  #2 (permalink)  
Old 09-23-2005, 07:01 AM
Kimmo Laine
Guest
 
Posts: n/a
Kimmo Laine RSS Feed
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


Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT. The time now is 10:59 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93