3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // The magic three sequence is the sum of the previous three values minus 1. // // 0,1,1,1,2,3,5, // // assume $n >= 0 function magicThree($n) { $n--; // To an index; $s = array(0,1,1,1); if ($n > 3) { for ($i = 0; $i < $n; $i++) { $s[$i] = $s[$i-1] + $s[$i-2] + $s[$i-3] - 1; } } else { $result = $s[$n]; } print $result; } magicThree(5); ?>
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -3 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined variable: result in /in/lsdte on line 27
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined index: -1 in /in/lsdte on line 19 Notice: Undefined index: -2 in /in/lsdte on line 19 Notice: Undefined index: -3 in /in/lsdte on line 19 Notice: Undefined index: -1 in /in/lsdte on line 19 Notice: Undefined index: -2 in /in/lsdte on line 19 Notice: Undefined index: -1 in /in/lsdte on line 19 Notice: Undefined variable: result in /in/lsdte on line 27
Output for 5.0.4 - 5.2.17
Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -3 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined variable: result in /in/lsdte on line 27
Output for 4.3.0 - 5.0.3
Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -3 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined offset: -2 in /in/lsdte on line 19 Notice: Undefined offset: -1 in /in/lsdte on line 19 Notice: Undefined variable: result in /in/lsdte on line 27