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++) { if(!count(array_intersect((array)$one[$i], (array)$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); } 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) { [0]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "f" } [1]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "g" } [2]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "h" } [3]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "f" } [4]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "g" } [5]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "h" } [6]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "f" } [7]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "g" } [8]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "h" } [9]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "f" } [10]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "g" } [11]=> array(5) { [0]=> string(1) "a" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "h" } [12]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "f" } [13]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "g" } [14]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "h" } [15]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "f" } [16]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "g" } [17]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "d" [2]=> string(1) "c" [3]=> string(1) "e" [4]=> string(1) "h" } [18]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "f" } [19]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "g" } [20]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "h" } [21]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "f" } [22]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "g" } [23]=> array(5) { [0]=> string(1) "b" [1]=> string(1) "e" [2]=> string(1) "c" [3]=> string(1) "d" [4]=> string(1) "h" } [24]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "f" } [25]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "g" } [26]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "a" [3]=> string(1) "e" [4]=> string(1) "h" } [27]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "f" } [28]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "g" } [29]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "d" [2]=> string(1) "b" [3]=> string(1) "e" [4]=> string(1) "h" } [30]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "f" } [31]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "g" } [32]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "a" [3]=> string(1) "d" [4]=> string(1) "h" } [33]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "f" } [34]=> array(5) { [0]=> string(1) "c" [1]=> string(1) "e" [2]=> string(1) "b" [3]=> string(1) "d" [4]=> string(1) "g" } [35]=> 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/783RY 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/783RY on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/783RY on line 4
Process exited with code 255.