1

I don't understand how the code editor gives me 20 as the output for the following PHP code:

<?php

  function sum2Numbers($x1)
  {
      static $x2 = 0;
      $x2 += $x1;
      return $x2;  
  }

  $sum = 10;

  for($m = 1; $m < 4; $m++)
    $sum += sum2Numbers($m); 

  echo $sum;
?>

I expect the output to be 16 but the actual output is 20. How?

Ivar
  • 6,138
  • 12
  • 49
  • 61
ACM
  • 19
  • 7

0 Answers0