nerdexam
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)
  • A
    17% (6)
  • B
    72% (26)
  • C
    8% (3)
  • D
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 200-500 Practice