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, Quote Link to comment 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"; } } } } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.