Given this code:
function doSomething( &$arg )
{
$return = $arg;
$arg += 1;
return $return;
}
$a = 3;
$b = doSomething( $a );
...what is the value of $a and $b after the function call and why?
what is the value of $a and $b after the function call and why?
Re: what is the value of $a and $b after the function call and why?
$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 (not a reference to) the initial value of the argument.
Return to “PHP, HTML, MYSQL and Web Hosting”
Who is online
Users browsing this forum: No registered users and 0 guests