National_Instruments
200-500 · Question #56
What is the output of the following script? 1 <?php 2 function fibonacci (&$x1 = 0, &$x2 = 1) 3 { 4 $result = $x1 + $x2; 5 $x1 = $x2; 6 $x2 = $result; 8 return $result; 9 } 11 for ($i = 0; $i < 10…
The correct answer is B. 1,1,1,1,1,1,1,1,1,1. See the full explanation below for the reasoning.
Question
What is the output of the following script? 1 <?php 2 function fibonacci (&$x1 = 0, &$x2 = 1) 3 { 4 $result = $x1 + $x2; 5 $x1 = $x2; 6 $x2 = $result; 8 return $result; 9 } 11 for ($i = 0; $i < 10; $i++) { 12 echo fibonacci() . ','; 13 } 14 ?>
Options
- AAn error
- B1,1,1,1,1,1,1,1,1,1,
- C1,1,2,3,5,8,13,21,34,55,
- DNothing
How the community answered
(36 responses)- A17% (6)
- B72% (26)
- C8% (3)
- D3% (1)
Community Discussion
No community discussion yet for this question.