centenial Posted February 16, 2010 Share Posted February 16, 2010 Hi, I have a multidimensional array that looks like this s t r 1 2 3 I want to print out the possible permutations of this into one string. Something like this: str st3 s2r s23 1tr 1t3 123 Can anyone think of a way to do this? Much appreciated, Link to comment https://forums.phpfreaks.com/topic/192286-permutations-of-a-multi-dimensional-array/ Share on other sites More sharing options...
Psycho Posted February 16, 2010 Share Posted February 16, 2010 Here's a quick and dirty solution. <?php $data = array ('s', 't', 'r', '1', '2', '3'); foreach($data as $char1) { foreach($data as $char2) { if ($char2 != $char1) { foreach($data as $char3) { if ($char3!=$char1 && $char3!=$char2) { echo "{$char1}{$char2}{$char3}<br />\n"; } } } } } ?> Link to comment https://forums.phpfreaks.com/topic/192286-permutations-of-a-multi-dimensional-array/#findComment-1013315 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.