3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function doLoad(array $weights, $remainingWeight, array $sequence = []) { if ($remainingWeight === 0) { return [$sequence]; } if (empty($weights)) { return []; } $container = array_shift($weights); $sequences = doLoad($weights, $remainingWeight, $sequence); if ($container <= $remainingWeight) { $sequence[] = $container; $sequences = array_merge($sequences, $this->doLoad($weights, ($remainingWeight - $container), $sequence)); } return $sequences; } $weights = [ 1, 3, 5, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113 ]; var_dump(doLoad($weights, 381));
Output for 7.0.0 - 7.2.0
Fatal error: Uncaught Error: Using $this when not in object context in /in/7tHsa:15 Stack trace: #0 /in/7tHsa(12): doLoad(Array, 381, Array) #1 /in/7tHsa(12): doLoad(Array, 381, Array) #2 /in/7tHsa(12): doLoad(Array, 381, Array) #3 /in/7tHsa(12): doLoad(Array, 381, Array) #4 /in/7tHsa(12): doLoad(Array, 381, Array) #5 /in/7tHsa(12): doLoad(Array, 381, Array) #6 /in/7tHsa(12): doLoad(Array, 381, Array) #7 /in/7tHsa(12): doLoad(Array, 381, Array) #8 /in/7tHsa(12): doLoad(Array, 381, Array) #9 /in/7tHsa(12): doLoad(Array, 381, Array) #10 /in/7tHsa(12): doLoad(Array, 381, Array) #11 /in/7tHsa(12): doLoad(Array, 381, Array) #12 /in/7tHsa(12): doLoad(Array, 381, Array) #13 /in/7tHsa(12): doLoad(Array, 381, Array) #14 /in/7tHsa(12): doLoad(Array, 381, Array) #15 /in/7tHsa(12): doLoad(Array, 381, Array) #16 /in/7tHsa(12): doLoad(Array, 381, Array) #17 /in/7tHsa(12): doLoad(Array, 381, Array) #18 /in/7tHsa(12): doLoad(Array, 381, Array) #19 /in/7tHsa(12): doLoad(Array, 381, Array) #20 /in/7tHsa(12): doLoad(Array, 381, Array) #21 / in /in/7tHsa on line 15
Process exited with code 255.
Output for 5.4.11 - 5.6.28
Fatal error: Using $this when not in object context in /in/7tHsa on line 15
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7tHsa on line 3
Process exited with code 255.