1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Functional programming

Discussion in 'PHP' started by keenlearner, Dec 31, 2007.

  1. #1
    I need to do a few functional programming in PHP, here is the code but it only prints out "arg2" but not "arg1". Thank you.

    
    function prints($arg1, $arg2)
    {
      echo $arg1. $arg2;
    }
    
    
    function applyOne($arg1)
    {
      $f =  create_function('$arg2', 'return prints("$arg1", $arg2);');
      return $f;
    }
    
    $printFunction = applyOne("arg1");
    
    $printFunction('arg2');
    
    
    PHP:

     
    keenlearner, Dec 31, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    $arg2 is unset in your applyOne function. What do you want it to output?
     
    nico_swd, Dec 31, 2007 IP
  3. keenlearner

    keenlearner Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I want it to output 'arg1arg2';
     
    keenlearner, Dec 31, 2007 IP