3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * take the range of characters and generate a string of all permutations * * @param array $range range of characters to itterate over * @param array $array input array - operated on by reference * @param int $depth how many chars to put in the resultant array should be * @param int $currentDepth internal variable to track how nested the current call is * @param string $prefix internal variable to know what to prefix the current string with * @return string permutations */ function foo($range, &$array, $depth = 1, $currentDepth = 0, $prefix = "") { $start = !$currentDepth; $currentDepth++; if ($currentDepth > $depth) { return; } foreach($range as $char) { if ($currentDepth === $depth) { $array[] = $prefix . $char; continue; } foo($range, $array, $depth, $currentDepth, $prefix . $char); } if ($start) { return implode($array, "\n"); } } $return = array(); echo foo(range('a', 'z'), $return, 2);
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in /in/DOVNs:31 Stack trace: #0 /in/DOVNs(31): implode(Array, '\n') #1 /in/DOVNs(36): foo(Array, Array, 2) #2 {main} thrown in /in/DOVNs on line 31
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
50.88 ms | 401 KiB | 8 Q