3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function decartProduct($one, $two) { $result = []; for($i=0; $i<count($one); $i++) { for($j=0; $j<count($two); $j++) { $result[]=array_merge((array)$one[$i], (array)$two[$j]); } } return $result; } function createAssociation() { $args = func_get_args(); if(!count($args)) { return []; } $result = array_shift($args); while($array=array_shift($args)) { $result=decartProduct($result, $array); } $result = array_filter($result, function($tuple) { return array_unique($tuple)==$tuple; }); return $result; } $i[0] = ['a', 'b', 'c']; $i[1] = ['d', 'e']; $i[2] = ['a', 'b', 'c']; $i[3] = ['d', 'e']; $i[4] = ['f', 'g', 'h']; $result = call_user_func_array('createAssociation', $i); var_dump($result);
Output for 5.4.0 - 7.1.0
array(36) { [9]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "f" } [10]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "g" } [11]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "h" } [15]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "f" } [16]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "g" } [17]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "h" } [24]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "f" } [25]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "g" } [26]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "h" } [30]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "f" } [31]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "g" } [32]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "h" } [39]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "f" } [40]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "g" } [41]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "h" } [51]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "f" } [52]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "g" } [53]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "h" } [54]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "f" } [55]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "g" } [56]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "h" } [66]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "f" } [67]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "g" } [68]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "h" } [75]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "f" } [76]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "g" } [77]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "h" } [81]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "f" } [82]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "g" } [83]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "h" } [90]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "f" } [91]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "g" } [92]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "h" } [96]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "f" } [97]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "g" } [98]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "h" } }
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/vrmGm on line 4
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/vrmGm on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/vrmGm on line 4
Process exited with code 255.