3v4l.org

run code in 300+ PHP versions simultaneously
<?php function powerSet($n, $minLength=2) { $in = range(1,$n); $count = count($in); $members = pow(2,$count); $return = array(); for ($i = 0; $i < $members; $i++) { $b = sprintf("%0".$count."b",$i); $out = array(); for ($j = 0; $j < $count; $j++) { if ($b{$j} == '1') $out[] = $in[$j]; } if (count($out) >= 2) { $return[] = $out; } } sort($return); return $return; } echo "\nFor n=2 \n"; foreach(powerSet(2) as $item) { echo implode(",",$item)."\n"; } echo "\nFor n=3 \n"; foreach(powerSet(3) as $item) { echo implode(",",$item)."\n"; } echo "\nFor n=4 \n"; foreach(powerSet(4) as $item) { echo implode(",",$item)."\n"; } echo "\nFor n=5 \n"; foreach(powerSet(5) as $item) { echo implode(",",$item)."\n"; }
Output for 8.4.1 - 8.4.14
Parse error: syntax error, unexpected token "{" in /in/kIKrU on line 12
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27
Fatal error: Array and string offset access syntax with curly braces is no longer supported in /in/kIKrU on line 12
Process exited with code 255.
Output for 7.4.0 - 7.4.33
Deprecated: Array and string offset access syntax with curly braces is deprecated in /in/kIKrU on line 12 For n=2 1,2 For n=3 1,2 1,3 2,3 1,2,3 For n=4 1,2 1,3 1,4 2,3 2,4 3,4 1,2,3 1,2,4 1,3,4 2,3,4 1,2,3,4 For n=5 1,2 1,3 1,4 1,5 2,3 2,4 2,5 3,4 3,5 4,5 1,2,3 1,2,4 1,2,5 1,3,4 1,3,5 1,4,5 2,3,4 2,3,5 2,4,5 3,4,5 1,2,3,4 1,2,3,5 1,2,4,5 1,3,4,5 2,3,4,5 1,2,3,4,5
Output for 5.6.38, 7.1.26 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
For n=2 1,2 For n=3 1,2 1,3 2,3 1,2,3 For n=4 1,2 1,3 1,4 2,3 2,4 3,4 1,2,3 1,2,4 1,3,4 2,3,4 1,2,3,4 For n=5 1,2 1,3 1,4 1,5 2,3 2,4 2,5 3,4 3,5 4,5 1,2,3 1,2,4 1,2,5 1,3,4 1,3,5 1,4,5 2,3,4 2,3,5 2,4,5 3,4,5 1,2,3,4 1,2,3,5 1,2,4,5 1,3,4,5 2,3,4,5 1,2,3,4,5

preferences:
227.49 ms | 411 KiB | 5 Q