3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php foreach (cartesian(expand_pattern('a..c'), 3) as $option) { echo "$option\n"; } function expand_pattern($pattern) { $bias = 0; $flags = PREG_SET_ORDER | PREG_OFFSET_CAPTURE; preg_match_all('/(.)\.\.(.)/', $pattern, $matches, $flags); foreach ($matches as $match) { $range = implode('', range($match[1][0], $match[2][0])); $pattern = substr_replace( $pattern, $range, $bias + $match[1][1], $match[2][1] - $match[1][1] + 1); $bias += strlen($range) - 4; } return $pattern; } function cartesian($pattern, $length) { $choices = strlen($pattern); $indexes = array_fill(0, $length, 0); $resets = 0; while ($resets != $length) { $result = ''; for ($i = 0; $i < $length; ++$i) { $result .= $pattern[$indexes[$i]]; } yield $result; $resets = 0; for ($i = $length - 1; $i >= 0 && ++$indexes[$i] == $choices; --$i) { $indexes[$i] = 0; ++$resets; } } }
based on F8dk0
Output for 5.5.24 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
aaa aab aac aba abb abc aca acb acc baa bab bac bba bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb ccc
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$result' (T_VARIABLE) in /in/88FC2 on line 36
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/88FC2 on line 36
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_VARIABLE in /in/88FC2 on line 36
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/88FC2 on line 36
Process exited with code 255.