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); foreach($combinations as $item) { echo $item.'<BR>'; }
Output for 5.4.0 - 5.6.25, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0RC4
Happy Outgoing Tall Handsome<BR> Happy Outgoing Tall Plain<BR> Happy Outgoing Tall Ugly<BR> Happy Outgoing Short Handsome<BR> Happy Outgoing Short Plain<BR> Happy Outgoing Short Ugly<BR> Happy Outgoing Medium Handsome<BR> Happy Outgoing Medium Plain<BR> Happy Outgoing Medium Ugly<BR> Happy Introverted Tall Handsome<BR> Happy Introverted Tall Plain<BR> Happy Introverted Tall Ugly<BR> Happy Introverted Short Handsome<BR> Happy Introverted Short Plain<BR> Happy Introverted Short Ugly<BR> Happy Introverted Medium Handsome<BR> Happy Introverted Medium Plain<BR> Happy Introverted Medium Ugly<BR> Sad Outgoing Tall Handsome<BR> Sad Outgoing Tall Plain<BR> Sad Outgoing Tall Ugly<BR> Sad Outgoing Short Handsome<BR> Sad Outgoing Short Plain<BR> Sad Outgoing Short Ugly<BR> Sad Outgoing Medium Handsome<BR> Sad Outgoing Medium Plain<BR> Sad Outgoing Medium Ugly<BR> Sad Introverted Tall Handsome<BR> Sad Introverted Tall Plain<BR> Sad Introverted Tall Ugly<BR> Sad Introverted Short Handsome<BR> Sad Introverted Short Plain<BR> Sad Introverted Short Ugly<BR> Sad Introverted Medium Handsome<BR> Sad Introverted Medium Plain<BR> Sad Introverted Medium Ugly<BR> Angry Outgoing Tall Handsome<BR> Angry Outgoing Tall Plain<BR> Angry Outgoing Tall Ugly<BR> Angry Outgoing Short Handsome<BR> Angry Outgoing Short Plain<BR> Angry Outgoing Short Ugly<BR> Angry Outgoing Medium Handsome<BR> Angry Outgoing Medium Plain<BR> Angry Outgoing Medium Ugly<BR> Angry Introverted Tall Handsome<BR> Angry Introverted Tall Plain<BR> Angry Introverted Tall Ugly<BR> Angry Introverted Short Handsome<BR> Angry Introverted Short Plain<BR> Angry Introverted Short Ugly<BR> Angry Introverted Medium Handsome<BR> Angry Introverted Medium Plain<BR> Angry Introverted Medium Ugly<BR> Hopeful Outgoing Tall Handsome<BR> Hopeful Outgoing Tall Plain<BR> Hopeful Outgoing Tall Ugly<BR> Hopeful Outgoing Short Handsome<BR> Hopeful Outgoing Short Plain<BR> Hopeful Outgoing Short Ugly<BR> Hopeful Outgoing Medium Handsome<BR> Hopeful Outgoing Medium Plain<BR> Hopeful Outgoing Medium Ugly<BR> Hopeful Introverted Tall Handsome<BR> Hopeful Introverted Tall Plain<BR> Hopeful Introverted Tall Ugly<BR> Hopeful Introverted Short Handsome<BR> Hopeful Introverted Short Plain<BR> Hopeful Introverted Short Ugly<BR> Hopeful Introverted Medium Handsome<BR> Hopeful Introverted Medium Plain<BR> Hopeful Introverted Medium Ugly<BR>
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/kvWns 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/kvWns on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/kvWns on line 4
Process exited with code 255.