473,799 Members | 3,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($func tion_to_execute )
{...bla... $function_to_ex ecute() ...bla....}

AND how to pass the variable of the function :

function f_example($func tion_to_execute ($var1,$var2))
{...bla... $function_to_ex ecute() ...bla....}

Thank you in advance for the time you'll spend for me,
Andrea.
Sep 23 '05 #1
6 1582
I'm sorry, I don't quite understand what you are asking...

If you are asking how to use results of a function in another function
then you should do this.

function test1()
{
return "Hello World!";
}

function test2($string)
{

}

test2(test1());
or
$moo = test1();
test2($moo);

Will output *Hello World!*

*************** **

If you are asking how you can execute a function inside another
function, then thats exactly what you do... just call it in the code.

Hope it helps, if not try reading the PHP manual under the
functions/syntax section.

Cheers,
D

_andrea.l wrote:
I'd like to write a function like:

function f(){ ... bla ...}
f_example(f);

function f_example($func tion_to_execute )
{...bla... $function_to_ex ecute() ...bla....}

AND how to pass the variable of the function :

function f_example($func tion_to_execute ($var1,$var2))
{...bla... $function_to_ex ecute() ...bla....}

Thank you in advance for the time you'll spend for me,
Andrea.

Sep 23 '05 #2
EDIT!

function test2($string)
{
echo $string;
}

Ramon wrote:
I'm sorry, I don't quite understand what you are asking...

If you are asking how to use results of a function in another function
then you should do this.

function test1()
{
return "Hello World!";
}

function test2($string)
{

}

test2(test1());
or
$moo = test1();
test2($moo);

Will output *Hello World!*

*************** **

If you are asking how you can execute a function inside another
function, then thats exactly what you do... just call it in the code.

Hope it helps, if not try reading the PHP manual under the
functions/syntax section.

Cheers,
D

_andrea.l wrote:
I'd like to write a function like:

function f(){ ... bla ...}
f_example(f);

function f_example($func tion_to_execute )
{...bla... $function_to_ex ecute() ...bla....}

AND how to pass the variable of the function :

function f_example($func tion_to_execute ($var1,$var2))
{...bla... $function_to_ex ecute() ...bla....}

Thank you in advance for the time you'll spend for me,
Andrea.

Sep 23 '05 #3
Simple

function a($p)
{
return $p^2;
}

function b($c, $params)
{
return $c($params);
}

now pass the function a() to function b() as parameter with additional
param

$func_a = "a";
$result = b($func_a, 123)

thats it!!

Sep 23 '05 #4
On Fri, 23 Sep 2005 06:14:45 GMT, _andrea.l wrote:
I'd like to write a function like:

function f(){ ... bla ...}
f_example(f);

function f_example($func tion_to_execute )
{...bla... $function_to_ex ecute() ...bla....}

AND how to pass the variable of the function :

function f_example($func tion_to_execute ($var1,$var2))
{...bla... $function_to_ex ecute() ...bla....}

Thank you in advance for the time you'll spend for me,
Andrea.


Don't multipost, if you have to post to more than one group cross post so
that everyone sees all the answers.
Sep 23 '05 #5
> Don't multipost, if you have to post to more than one group cross post so
that everyone sees all the answers.

How can I do to cross post?
Thank you!
Andrea.
Sep 23 '05 #6
On Fri, 23 Sep 2005 19:54:17 GMT, _andrea.l wrote:
Don't multipost, if you have to post to more than one group cross post so
that everyone sees all the answers.

How can I do to cross post?
Thank you!
Andrea.


http://www.cs.tut.fi/~jkorpela/usenet/xpost.html
Sep 24 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2964
by: Stephen Williams | last post by:
Hey i've got bunch of arrays of tick boxes, each array contains somewhere between 5 and 20. What I want to do is write a function that returns the captions of every ticked tick box in an array as a string. I want to be able to pass to the function the array name, and the lower and upper limits of the array. But I have no idea how to pass the control name (array name).
28
4717
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
3
2507
by: QQ | last post by:
I have one integer array int A; I need to pass this array into a function and evaluate this array in this function how should I pass? Is it fine? void test(int *a)
4
10311
by: mwanstall | last post by:
Hi All, I have started tearing my hair out over this problem! I am pulling some data from a table and passing it as variables into a function in Access. One of the variables I'm passing through can be Null, so to avoid trying to pass a Null value to a function as a string (which I gather Access wouldn't like) I created an IIF function inside the parameters so if the value was null, it passed the string "NULLDEPOT" into the function, and I...
6
2714
by: lisp9000 | last post by:
I've read that C allows two ways to pass information between functions: o Pass by Value o Pass by Reference I was talking to some C programmers and they told me there is no such thing as pass by reference in C since you are just passing an address (or a pointer value address I guess?). So I was wondering is this correct?
11
3367
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible ways of passing an array. In the following code, fun1(int a1) - same as fun1(int* a1) - where both are of the type passed by reference. Inside this function, another pointer a1 is created whose address &a1 is different from that of the passed...
12
3020
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
9
2063
by: raylopez99 | last post by:
I'm posting this fragment from another thread to frame the issue clearer. How to pass an object to a function/method call in C# that will guarantee not to change the object?* In C++, as seen below, you can use the 'const' keyword in the function / method declaration. But how to do this in C#? *for example: "void Foo() const;"
12
11116
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
1
2569
by: kkshansid | last post by:
i want to pass both variables($q1 and value of select) from this php page to java script so that i can get both variables in second php file srt.php <script type="text/javascript" src="st.js"></script> <?php $q1=$_GET; require("conn.php"); $sql="SELECT distinct(".$q1.")FROM inst";
0
9543
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4144
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.