Zend
200-710 · Question #91
What is the output of the following code? function fibonacci (&$x1 = 0, &$x2 = 1) { $result = $x1 + $x2; $x1 = $x2; $x2 = $result; return $result; } for ($i = 0; $i < 10; $i++) { echo fibonacci()…
The correct answer is B. 1,1,1,1,1,1,1,1,1. See the full explanation below for the reasoning.
Functions
Question
What is the output of the following code?
function fibonacci (&$x1 = 0, &$x2 = 1)
{
$result = $x1 + $x2;
$x1 = $x2;
$x2 = $result;
return $result;
}
for ($i = 0; $i < 10; $i++) {
echo fibonacci() . ' , ';
}
Options
- AAn error
- B1,1,1,1,1,1,1,1,1
- C1,1,2,3,5,8,13,21,34,55
- DNothing
How the community answered
(54 responses)- A6% (3)
- B85% (46)
- C7% (4)
- D2% (1)
Topics
#default reference parameters#pass by reference#fibonacci#function state
Community Discussion
No community discussion yet for this question.