?
What is the value of $a and $b after the function call?
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 );
?>
<?php
function doSomething( &$arg )
{
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
?>
Answer & Solution
Correct Answer:
Option
B
$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.
Join the Discussion
Login to post a comment or share your explanation.
Login