3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function sum() { $list = array(); $prepare = function($value) use(&$prepare, &$list) { if (is_array($value)) { array_walk($value, $prepare, $list); } $list[] = $value; }; $args = func_get_args(); array_walk($args, $prepare, $list); var_dump($list); return addition(0, $list); } function addition($sum, array &$list) { return empty($list) ? $sum : addition($sum + array_pop($list), $list); } $vars = range(1, 10); echo sum(array($vars), array(1));
based on F6vE9
Output for 7.0.0 - 7.2.0
array(14) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) [10]=> array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) } [11]=> array(1) { [0]=> array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) } } [12]=> int(1) [13]=> array(1) { [0]=> int(1) } } Fatal error: Uncaught Error: Unsupported operand types in /in/9rHr2:21 Stack trace: #0 /in/9rHr2(17): addition(0, Array) #1 /in/9rHr2(25): sum(Array, Array) #2 {main} thrown in /in/9rHr2 on line 21
Process exited with code 255.
Output for 5.3.17 - 5.6.28
array(14) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) [10]=> array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) } [11]=> array(1) { [0]=> array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) } } [12]=> int(1) [13]=> array(1) { [0]=> int(1) } } Fatal error: Unsupported operand types in /in/9rHr2 on line 21
Process exited with code 255.