3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getCombinations($traits) { $combinations = ['']; foreach( $traits as $trait_level ) { $new_combinations = []; foreach ($combinations as $comb) { foreach ($trait_level as $trait) { $new_combinations[] = "$comb $trait"; } } $combinations = $new_combinations; } return $combinations; } $traits = array ( array('Happy', 'Sad', 'Angry', 'Hopeful'), array('Outgoing', 'Introverted'), array('Tall', 'Short', 'Medium'), array('Handsome', 'Plain', 'Ugly') ); $combinations = getCombinations($traits); print_r($combinations);
Output for 5.4.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => Happy Outgoing Tall Handsome [1] => Happy Outgoing Tall Plain [2] => Happy Outgoing Tall Ugly [3] => Happy Outgoing Short Handsome [4] => Happy Outgoing Short Plain [5] => Happy Outgoing Short Ugly [6] => Happy Outgoing Medium Handsome [7] => Happy Outgoing Medium Plain [8] => Happy Outgoing Medium Ugly [9] => Happy Introverted Tall Handsome [10] => Happy Introverted Tall Plain [11] => Happy Introverted Tall Ugly [12] => Happy Introverted Short Handsome [13] => Happy Introverted Short Plain [14] => Happy Introverted Short Ugly [15] => Happy Introverted Medium Handsome [16] => Happy Introverted Medium Plain [17] => Happy Introverted Medium Ugly [18] => Sad Outgoing Tall Handsome [19] => Sad Outgoing Tall Plain [20] => Sad Outgoing Tall Ugly [21] => Sad Outgoing Short Handsome [22] => Sad Outgoing Short Plain [23] => Sad Outgoing Short Ugly [24] => Sad Outgoing Medium Handsome [25] => Sad Outgoing Medium Plain [26] => Sad Outgoing Medium Ugly [27] => Sad Introverted Tall Handsome [28] => Sad Introverted Tall Plain [29] => Sad Introverted Tall Ugly [30] => Sad Introverted Short Handsome [31] => Sad Introverted Short Plain [32] => Sad Introverted Short Ugly [33] => Sad Introverted Medium Handsome [34] => Sad Introverted Medium Plain [35] => Sad Introverted Medium Ugly [36] => Angry Outgoing Tall Handsome [37] => Angry Outgoing Tall Plain [38] => Angry Outgoing Tall Ugly [39] => Angry Outgoing Short Handsome [40] => Angry Outgoing Short Plain [41] => Angry Outgoing Short Ugly [42] => Angry Outgoing Medium Handsome [43] => Angry Outgoing Medium Plain [44] => Angry Outgoing Medium Ugly [45] => Angry Introverted Tall Handsome [46] => Angry Introverted Tall Plain [47] => Angry Introverted Tall Ugly [48] => Angry Introverted Short Handsome [49] => Angry Introverted Short Plain [50] => Angry Introverted Short Ugly [51] => Angry Introverted Medium Handsome [52] => Angry Introverted Medium Plain [53] => Angry Introverted Medium Ugly [54] => Hopeful Outgoing Tall Handsome [55] => Hopeful Outgoing Tall Plain [56] => Hopeful Outgoing Tall Ugly [57] => Hopeful Outgoing Short Handsome [58] => Hopeful Outgoing Short Plain [59] => Hopeful Outgoing Short Ugly [60] => Hopeful Outgoing Medium Handsome [61] => Hopeful Outgoing Medium Plain [62] => Hopeful Outgoing Medium Ugly [63] => Hopeful Introverted Tall Handsome [64] => Hopeful Introverted Tall Plain [65] => Hopeful Introverted Tall Ugly [66] => Hopeful Introverted Short Handsome [67] => Hopeful Introverted Short Plain [68] => Hopeful Introverted Short Ugly [69] => Hopeful Introverted Medium Handsome [70] => Hopeful Introverted Medium Plain [71] => Hopeful Introverted Medium Ugly )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/BNTpa 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/BNTpa on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/BNTpa on line 4
Process exited with code 255.