what is the value of $a and $b after the function call and why?

It is for static page, dynamic page, website, SEO, performance and other web development discussion
ramverma
Posts: 435
Joined: Sat Aug 23, 2014 5:34 pm
Contact:

what is the value of $a and $b after the function call and why?

Postby ramverma » Mon Oct 19, 2015 6:15 am

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?


jeff2345
Posts: 49
Joined: Tue May 05, 2015 7:09 pm
Contact:

Re: what is the value of $a and $b after the function call and why?

Postby jeff2345 » Tue Oct 20, 2015 6:48 am

$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