3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [1,3,45,2,7,0,1,0]; echo removeZeroAndSumFirstThree(); function removeZeroAndSumFirstThree($arr) { asort($arr); //Remove 0 from array $a = array_diff($arr, [0]); $output = array_slice($a, 0, 3); return array_sum($output); }
Output for 7.1.0 - 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
Fatal error: Uncaught ArgumentCountError: Too few arguments to function removeZeroAndSumFirstThree(), 0 passed in /in/AIU2F on line 4 and exactly 1 expected in /in/AIU2F:6 Stack trace: #0 /in/AIU2F(4): removeZeroAndSumFirstThree() #1 {main} thrown in /in/AIU2F on line 6
Process exited with code 255.
Output for 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20
Warning: Missing argument 1 for removeZeroAndSumFirstThree(), called in /in/AIU2F on line 4 and defined in /in/AIU2F on line 6 Warning: asort() expects parameter 1 to be array, null given in /in/AIU2F on line 7 Warning: array_diff(): Argument #1 is not an array in /in/AIU2F on line 9 Warning: array_slice() expects parameter 1 to be array, null given in /in/AIU2F on line 10 Warning: array_sum() expects parameter 1 to be array, null given in /in/AIU2F on line 11

preferences:
94.71 ms | 1704 KiB | 4 Q