3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $products = [1, 2, 3, 4, 5]; $vendors = ["Amazon", "Newegg", "Frys"]; $combinations = array(); function pc_permute($items, $perms = array()) { global $combinations; if (empty($items)) { //echo join(' ', $perms); //var_dump($perms); $combinations[] = $perms; } else { for ($i = count($items) - 1; $i >= 0; --$i) { $newitems = $items; $newperms = $perms; list($foo) = array_splice($newitems, $i, 1); array_unshift($newperms, $foo); pc_permute($newitems, $newperms); } } } pc_permute($products); var_dump($combinations);
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
array(120) { [0]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) } [1]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(3) [3]=> int(4) [4]=> int(5) } [2]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(2) [3]=> int(4) [4]=> int(5) } [3]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(2) [3]=> int(4) [4]=> int(5) } [4]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(1) [3]=> int(4) [4]=> int(5) } [5]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(1) [3]=> int(4) [4]=> int(5) } [6]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(4) [3]=> int(3) [4]=> int(5) } [7]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(4) [3]=> int(3) [4]=> int(5) } [8]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(2) [3]=> int(3) [4]=> int(5) } [9]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(5) } [10]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(1) [3]=> int(3) [4]=> int(5) } [11]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(1) [3]=> int(3) [4]=> int(5) } [12]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(4) [3]=> int(2) [4]=> int(5) } [13]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(4) [3]=> int(2) [4]=> int(5) } [14]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(3) [3]=> int(2) [4]=> int(5) } [15]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(3) [3]=> int(2) [4]=> int(5) } [16]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(1) [3]=> int(2) [4]=> int(5) } [17]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(1) [3]=> int(2) [4]=> int(5) } [18]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(1) [4]=> int(5) } [19]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(4) [3]=> int(1) [4]=> int(5) } [20]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(3) [3]=> int(1) [4]=> int(5) } [21]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(3) [3]=> int(1) [4]=> int(5) } [22]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(2) [3]=> int(1) [4]=> int(5) } [23]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(2) [3]=> int(1) [4]=> int(5) } [24]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(5) [4]=> int(4) } [25]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(3) [3]=> int(5) [4]=> int(4) } [26]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(2) [3]=> int(5) [4]=> int(4) } [27]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(2) [3]=> int(5) [4]=> int(4) } [28]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(1) [3]=> int(5) [4]=> int(4) } [29]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(1) [3]=> int(5) [4]=> int(4) } [30]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(5) [3]=> int(3) [4]=> int(4) } [31]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(5) [3]=> int(3) [4]=> int(4) } [32]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(2) [3]=> int(3) [4]=> int(4) } [33]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) } [34]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(1) [3]=> int(3) [4]=> int(4) } [35]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(1) [3]=> int(3) [4]=> int(4) } [36]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(5) [3]=> int(2) [4]=> int(4) } [37]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(5) [3]=> int(2) [4]=> int(4) } [38]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(3) [3]=> int(2) [4]=> int(4) } [39]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(3) [3]=> int(2) [4]=> int(4) } [40]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(1) [3]=> int(2) [4]=> int(4) } [41]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(1) [3]=> int(2) [4]=> int(4) } [42]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(5) [3]=> int(1) [4]=> int(4) } [43]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(5) [3]=> int(1) [4]=> int(4) } [44]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(3) [3]=> int(1) [4]=> int(4) } [45]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(3) [3]=> int(1) [4]=> int(4) } [46]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(2) [3]=> int(1) [4]=> int(4) } [47]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(2) [3]=> int(1) [4]=> int(4) } [48]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(4) [3]=> int(5) [4]=> int(3) } [49]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(4) [3]=> int(5) [4]=> int(3) } [50]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(2) [3]=> int(5) [4]=> int(3) } [51]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(2) [3]=> int(5) [4]=> int(3) } [52]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(1) [3]=> int(5) [4]=> int(3) } [53]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(1) [3]=> int(5) [4]=> int(3) } [54]=> array(5) { [0]=> int(1) [1]=> int(2) [2]=> int(5) [3]=> int(4) [4]=> int(3) } [55]=> array(5) { [0]=> int(2) [1]=> int(1) [2]=> int(5) [3]=> int(4) [4]=> int(3) } [56]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(2) [3]=> int(4) [4]=> int(3) } [57]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(2) [3]=> int(4) [4]=> int(3) } [58]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(1) [3]=> int(4) [4]=> int(3) } [59]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(1) [3]=> int(4) [4]=> int(3) } [60]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(5) [3]=> int(2) [4]=> int(3) } [61]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(5) [3]=> int(2) [4]=> int(3) } [62]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(4) [3]=> int(2) [4]=> int(3) } [63]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(4) [3]=> int(2) [4]=> int(3) } [64]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(1) [3]=> int(2) [4]=> int(3) } [65]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(1) [3]=> int(2) [4]=> int(3) } [66]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(5) [3]=> int(1) [4]=> int(3) } [67]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(5) [3]=> int(1) [4]=> int(3) } [68]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(4) [3]=> int(1) [4]=> int(3) } [69]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(4) [3]=> int(1) [4]=> int(3) } [70]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(2) [3]=> int(1) [4]=> int(3) } [71]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(2) [3]=> int(1) [4]=> int(3) } [72]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> int(2) } [73]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(4) [3]=> int(5) [4]=> int(2) } [74]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(3) [3]=> int(5) [4]=> int(2) } [75]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(3) [3]=> int(5) [4]=> int(2) } [76]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(1) [3]=> int(5) [4]=> int(2) } [77]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(1) [3]=> int(5) [4]=> int(2) } [78]=> array(5) { [0]=> int(1) [1]=> int(3) [2]=> int(5) [3]=> int(4) [4]=> int(2) } [79]=> array(5) { [0]=> int(3) [1]=> int(1) [2]=> int(5) [3]=> int(4) [4]=> int(2) } [80]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(3) [3]=> int(4) [4]=> int(2) } [81]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(3) [3]=> int(4) [4]=> int(2) } [82]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(1) [3]=> int(4) [4]=> int(2) } [83]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(1) [3]=> int(4) [4]=> int(2) } [84]=> array(5) { [0]=> int(1) [1]=> int(4) [2]=> int(5) [3]=> int(3) [4]=> int(2) } [85]=> array(5) { [0]=> int(4) [1]=> int(1) [2]=> int(5) [3]=> int(3) [4]=> int(2) } [86]=> array(5) { [0]=> int(1) [1]=> int(5) [2]=> int(4) [3]=> int(3) [4]=> int(2) } [87]=> array(5) { [0]=> int(5) [1]=> int(1) [2]=> int(4) [3]=> int(3) [4]=> int(2) } [88]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(1) [3]=> int(3) [4]=> int(2) } [89]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(1) [3]=> int(3) [4]=> int(2) } [90]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(5) [3]=> int(1) [4]=> int(2) } [91]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(5) [3]=> int(1) [4]=> int(2) } [92]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(4) [3]=> int(1) [4]=> int(2) } [93]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(4) [3]=> int(1) [4]=> int(2) } [94]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(3) [3]=> int(1) [4]=> int(2) } [95]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(3) [3]=> int(1) [4]=> int(2) } [96]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(4) [3]=> int(5) [4]=> int(1) } [97]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(4) [3]=> int(5) [4]=> int(1) } [98]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(3) [3]=> int(5) [4]=> int(1) } [99]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(3) [3]=> int(5) [4]=> int(1) } [100]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(2) [3]=> int(5) [4]=> int(1) } [101]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(2) [3]=> int(5) [4]=> int(1) } [102]=> array(5) { [0]=> int(2) [1]=> int(3) [2]=> int(5) [3]=> int(4) [4]=> int(1) } [103]=> array(5) { [0]=> int(3) [1]=> int(2) [2]=> int(5) [3]=> int(4) [4]=> int(1) } [104]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(3) [3]=> int(4) [4]=> int(1) } [105]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(1) } [106]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(2) [3]=> int(4) [4]=> int(1) } [107]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(2) [3]=> int(4) [4]=> int(1) } [108]=> array(5) { [0]=> int(2) [1]=> int(4) [2]=> int(5) [3]=> int(3) [4]=> int(1) } [109]=> array(5) { [0]=> int(4) [1]=> int(2) [2]=> int(5) [3]=> int(3) [4]=> int(1) } [110]=> array(5) { [0]=> int(2) [1]=> int(5) [2]=> int(4) [3]=> int(3) [4]=> int(1) } [111]=> array(5) { [0]=> int(5) [1]=> int(2) [2]=> int(4) [3]=> int(3) [4]=> int(1) } [112]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(2) [3]=> int(3) [4]=> int(1) } [113]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(2) [3]=> int(3) [4]=> int(1) } [114]=> array(5) { [0]=> int(3) [1]=> int(4) [2]=> int(5) [3]=> int(2) [4]=> int(1) } [115]=> array(5) { [0]=> int(4) [1]=> int(3) [2]=> int(5) [3]=> int(2) [4]=> int(1) } [116]=> array(5) { [0]=> int(3) [1]=> int(5) [2]=> int(4) [3]=> int(2) [4]=> int(1) } [117]=> array(5) { [0]=> int(5) [1]=> int(3) [2]=> int(4) [3]=> int(2) [4]=> int(1) } [118]=> array(5) { [0]=> int(4) [1]=> int(5) [2]=> int(3) [3]=> int(2) [4]=> int(1) } [119]=> array(5) { [0]=> int(5) [1]=> int(4) [2]=> int(3) [3]=> int(2) [4]=> int(1) } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Rg7i4 on line 3
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 '[' in /in/Rg7i4 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Rg7i4 on line 3
Process exited with code 255.