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 );
?>
A. a is 3 and b is 4
B. a is 4 and b is 3
C. Both are 3
D. Both are 4
Answer: Option B
Solution(By Examveda Team)
$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.Related Questions on Basic PHP
A. Both 1 and 3
B. Both 2 and 4
C. Only 2
D. Both 1 and 2
Which of the following is/are a PHP code editor?
1. Notepad
2. Notepad++
3. Adobe Dreamweaver
4. PDT
A. Only 4
B. All of the mentioned
C. 1, 2 and 3
D. Only 3
A. All of the mentioned.
B. Only 2
C. 2 and 3
D. 2, 3 and 4
Join The Discussion