3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = ['a', 'b', 'c', 'd','e','f','g']; function combinations($array, $k) { if ($k === 0) { return [[]]; } if (count($array) === $k) { return [$array]; } if (count($array) < $k) { return []; } $results = []; list($firstElem, $restArray) = [array_slice($array, 0, 1), array_slice($array, 1)]; foreach (combinations($restArray, $k - 1) as $combination) { $results[] = array_merge($firstElem, $combination); } foreach (combinations($restArray, $k) as $combination) { $results[] = $combination; } return $results; } $combinations = array_map('implode', combinations($array, 2)); print_r($combinations); ?>
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [0] => ab [1] => ac [2] => ad [3] => ae [4] => af [5] => ag [6] => bc [7] => bd [8] => be [9] => bf [10] => bg [11] => cd [12] => ce [13] => cf [14] => cg [15] => de [16] => df [17] => dg [18] => ef [19] => eg [20] => fg )

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:
100.05 ms | 406 KiB | 5 Q