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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • _andrea.l

    #1

    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.


  • Ramon

    #2
    Re: How to pass a function to a function?, and how to pass the variablesof the function?

    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:[color=blue]
    > 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.
    >
    >[/color]

    Comment

    • Ramon

      #3
      Re: How to pass a function to a function?, and how to pass the variablesof the function?

      EDIT!

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



      Ramon wrote:[color=blue]
      > 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:
      >[color=green]
      >> 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.
      >>
      >>[/color][/color]

      Comment

      • CountDraculla

        #4
        Re: How to pass a function to a function?, and how to pass the variables of the function?

        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!!

        Comment

        • Obvious

          #5
          Re: How to pass a function to a function?, and how to pass the variables of the function?

          On Fri, 23 Sep 2005 06:14:45 GMT, _andrea.l wrote:
          [color=blue]
          > 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.[/color]

          Don't multipost, if you have to post to more than one group cross post so
          that everyone sees all the answers.

          Comment

          • _andrea.l

            #6
            Re: How to pass a function to a function?, and how to pass the variables of the function?

            > Don't multipost, if you have to post to more than one group cross post so[color=blue]
            > that everyone sees all the answers.[/color]
            How can I do to cross post?
            Thank you!
            Andrea.


            Comment

            • Obvious

              #7
              Re: How to pass a function to a function?, and how to pass the variables of the function?

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


              Comment

              Working...