3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $str = "800"; function getCombinations($array) { //initalize array $results = [[]]; //get all combinations foreach ($array as $k => $element) { foreach ($results as $combination) $results[] = $combination + [$k => $element]; } //return filtered array return array_values(array_filter($results)); } $arr = getCombinations(str_split($str, "")); foreach($arr as $v) echo implode(" ", $v) . "<br />";
based on ONhqt
Output for 7.0.0 - 7.2.0
Warning: str_split() expects parameter 2 to be integer, string given in /in/h0TBV on line 23 Warning: Invalid argument supplied for foreach() in /in/h0TBV on line 12
Output for 5.4.11 - 5.6.28
Warning: str_split() expects parameter 2 to be long, string given in /in/h0TBV on line 23 Warning: Invalid argument supplied for foreach() in /in/h0TBV on line 12
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/h0TBV on line 9
Process exited with code 255.