Home / CSE / PHP - CS :: Discussion

Discussion :: PHP - CS

  1. What is the value of $a and $b after the function call?

    <?php

    function doSomething( &$arg )

    {

    $return = $arg;

    $arg += 1;

    return $return;

    }

    $a = 3;

    $b = doSomething( $a );

    ?>

  2. A.

     a is 3 and b is 4

    B.

     a is 4 and b is 3

    C.

     Both are 3

    D.

     Both are 4

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    $a is 4 and $b is 3. The former because $arg is passed by reference, the latter because the return value of the function is a copy of the initial value of the argument.


Be The First To Comment