473,396 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.
Sep 23 '05 #1
6 1561
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($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.

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($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.

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($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.


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
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...
28
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
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
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...
6
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...
11
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...
12
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....
9
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...
12
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....
1
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"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.