Here is my first cut at the problem. It is probably not the most optimal
solution in terms of algorithmic complexity and it could also do without
the use of global vars and such, but it should give you some ideas.

[code]

$arr = array('word1', 'word2', 'word3');

$lowerBound = 1;
$upperBound = pow(2, count($arr)) - 1;

for ($index = $lowerBound; $index <= $upperBound; ++$index) {
        
        $bitString = str_pad(decbin($index), count($arr), 0,
STR_PAD_LEFT);

        echo showValues($bitString) . "<br>";
        
}

function showValues($bitString) {
        
        global $arr;
        
        $outputStringArray = array();

        for ($pos = 0; $pos < strlen($bitString); ++$pos) {
                
                if ($bitString[$pos]) {
                        
                        $outputStringArray[] = $arr[$pos];
                }
                
        }
        
        return implode(' ', $outputStringArray);
        
        
}
[/code]

Shaunak Kashyap
 
Senior Web Developer
WPT Enterprises, Inc.
5700 Wilshire Blvd., Suite 350
Los Angeles, CA 90036
 
Direct: 323.330.9870
Main: 323.330.9900
 
www.worldpokertour.com
 
Confidentiality Notice:  This e-mail transmission (and/or the
attachments accompanying) it may contain confidential information
belonging to the sender which is protected.  The information is intended
only for the use of the intended recipient.  If you are not the intended
recipient, you are hereby notified that any disclosure, copying,
distribution or taking of any action in reliance on the contents of this
information is prohibited. If you have received this transmission in
error, please notify the sender by reply e-mail and destroy all copies
of this transmission.


> -----Original Message-----
> From: Mike Dunlop [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, March 28, 2006 11:57 AM
> To: Shaunak Kashyap
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] word matrix
> 
> no, just all the unique combinations. Thanks!
> 
> ...................................................................
> Mike Dunlop
> Director of Technology Development
> [ e ] [EMAIL PROTECTED]
> [ p ] 323.644.7808
> 
> 
> On Mar 28, 2006, at 11:42 AM, Shaunak Kashyap wrote:
> 
> > Would you also want the following combinations?
> >
> > "word1 word3 word2"
> > "word2 word1 word3"
> > "word2 word3 word1"
> > "word3 word1 word2"
> > "word3 word2 word1"
> >
> > Shaunak Kashyap
> >
> > Senior Web Developer
> > WPT Enterprises, Inc.
> > 5700 Wilshire Blvd., Suite 350
> > Los Angeles, CA 90036
> >
> > Direct: 323.330.9870
> > Main: 323.330.9900
> >
> > www.worldpokertour.com
> >
> > Confidentiality Notice:  This e-mail transmission (and/or the
> > attachments accompanying) it may contain confidential information
> > belonging to the sender which is protected.  The information is
> > intended
> > only for the use of the intended recipient.  If you are not the
> > intended
> > recipient, you are hereby notified that any disclosure, copying,
> > distribution or taking of any action in reliance on the contents of
> > this
> > information is prohibited. If you have received this transmission in
> > error, please notify the sender by reply e-mail and destroy all
copies
> > of this transmission.
> >
> >
> >> -----Original Message-----
> >> From: Mike Dunlop [mailto:[EMAIL PROTECTED]
> >> Sent: Tuesday, March 28, 2006 11:36 AM
> >> To: Chris
> >> Cc: php-general@lists.php.net
> >> Subject: Re: [PHP] word matrix
> >>
> >> Sure Chris.
> >>
> >> $words = array("word1","word2","word3");
> >>
> >> I want this:
> >>
> >> $result = array(
> >>    "word1",
> >>    "word2",
> >>    "word3",
> >>    "word1 word2",
> >>    "word1 word3",
> >>    "word2 word1",
> >>    "word2 word3",
> >>    "word3 word1",
> >>    "word3 word2",
> >>    "word1,word2,word3"
> >> );
> >>
> >>
> >> Thanks - MD
> >>
> >>
> >>
> >>
> >> On Mar 27, 2006, at 5:55 PM, Chris wrote:
> >>
> >>> Mike Dunlop wrote:
> >>>> i have an array of various words and am looking to create a
> >>>> result  array of every possible combination of words from the
orig
> >>>> array. I'm  not sure how to accomplish this elegantly within a
for
> >>>> loop. Anyone  have any ideas?
> >>>
> >>> Could you post a sample of what you have and what you want to end
> >>> up with?
> >>>
> >>> It'll be easier for us to work out rather than guess at what
you're
> >>> trying to do.
> >>>
> >>> --
> >>> Postgresql & php tutorials
> >>> http://www.designmagick.com/
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>
> >> --
> >> PHP General Mailing List (http://www.php.net/)
> >> To unsubscribe, visit: http://www.php.net/unsub.php
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to