3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getCombinedSum($digits, $sum) { if(!is_int($digits) || !is_int($sum) || $digits<1 || $sum<0) { throw new InvalidArgumentException('Invalid numeric format'); } if($sum>9*$digits) { throw new LogicException('Sum out of range'); } if($digits==1) { return [$sum]; } $result = []; for($digit=0; $digit<10 && $sum-$digit>0; $digit++) { $subsum = join('',getCombinedSum($digits-1, $sum-$digit))); for($j=0; $j<$digits; $j++) { $result[] = substr($subsum, 0, $j).$digit.substr($subsum, $j); } } return $result; } var_dump(getCombinedSum(3, 1));
Output for 5.4.0 - 5.4.22
Parse error: syntax error, unexpected ')' in /in/DFrHF on line 20
Process exited with code 255.
Output for 5.3.0 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/DFrHF on line 15
Process exited with code 255.