Little help for php function

Discussion in 'PHP' started by Om ji Kesharwani, Feb 23, 2010.

  1. #1
    
    <?php
    function a($n){
      b($n);
      return ($n * $n);
    }
    
    function b[COLOR="Red"](&$n)[/COLOR]{
      $n++;
    }
    
    echo a(5); //Outputs 36
    ?>
    Code (markup):
    What is the use of & in function b
     
    Om ji Kesharwani, Feb 23, 2010 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    shallowink, Feb 23, 2010 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Your code is working similar to as if $n is "global" variable. You can also use:
    
    function a($n){
    $n=b($n);
    return ($n * $n);
    }
    
    function b($n);
    ++$n;
    return $n;
    }
    
    Code (markup):
    Thanks :)
     
    JEET, Feb 23, 2010 IP