3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getCombinations($traits, $string = '', $i = 0) { $combinations = ''; if ($i >= count($traits)) return trim($string) . "\n"; else { foreach ($traits[$i] as $trait) { $combinations .= getCombinations($traits, "$string $trait", $i + 1); } } return $combinations; } $traits = array ( array('Happy', 'Sad', 'Angry', 'Hopeful'), array('Outgoing', 'Introverted'), array('Tall', 'Short', 'Medium'), array('Handsome', 'Plain', 'Ugly') ); $combinations = getCombinations($traits); // As a string echo $combinations; // As an array $combinationsArray = explode("\n",$combinations); print_r($combinationsArray);
Output for 4.3.0 - 7.1.0
Happy Outgoing Tall Handsome Happy Outgoing Tall Plain Happy Outgoing Tall Ugly Happy Outgoing Short Handsome Happy Outgoing Short Plain Happy Outgoing Short Ugly Happy Outgoing Medium Handsome Happy Outgoing Medium Plain Happy Outgoing Medium Ugly Happy Introverted Tall Handsome Happy Introverted Tall Plain Happy Introverted Tall Ugly Happy Introverted Short Handsome Happy Introverted Short Plain Happy Introverted Short Ugly Happy Introverted Medium Handsome Happy Introverted Medium Plain Happy Introverted Medium Ugly Sad Outgoing Tall Handsome Sad Outgoing Tall Plain Sad Outgoing Tall Ugly Sad Outgoing Short Handsome Sad Outgoing Short Plain Sad Outgoing Short Ugly Sad Outgoing Medium Handsome Sad Outgoing Medium Plain Sad Outgoing Medium Ugly Sad Introverted Tall Handsome Sad Introverted Tall Plain Sad Introverted Tall Ugly Sad Introverted Short Handsome Sad Introverted Short Plain Sad Introverted Short Ugly Sad Introverted Medium Handsome Sad Introverted Medium Plain Sad Introverted Medium Ugly Angry Outgoing Tall Handsome Angry Outgoing Tall Plain Angry Outgoing Tall Ugly Angry Outgoing Short Handsome Angry Outgoing Short Plain Angry Outgoing Short Ugly Angry Outgoing Medium Handsome Angry Outgoing Medium Plain Angry Outgoing Medium Ugly Angry Introverted Tall Handsome Angry Introverted Tall Plain Angry Introverted Tall Ugly Angry Introverted Short Handsome Angry Introverted Short Plain Angry Introverted Short Ugly Angry Introverted Medium Handsome Angry Introverted Medium Plain Angry Introverted Medium Ugly Hopeful Outgoing Tall Handsome Hopeful Outgoing Tall Plain Hopeful Outgoing Tall Ugly Hopeful Outgoing Short Handsome Hopeful Outgoing Short Plain Hopeful Outgoing Short Ugly Hopeful Outgoing Medium Handsome Hopeful Outgoing Medium Plain Hopeful Outgoing Medium Ugly Hopeful Introverted Tall Handsome Hopeful Introverted Tall Plain Hopeful Introverted Tall Ugly Hopeful Introverted Short Handsome Hopeful Introverted Short Plain Hopeful Introverted Short Ugly Hopeful Introverted Medium Handsome Hopeful Introverted Medium Plain Hopeful Introverted Medium Ugly 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 [72] => )