Finding combinations in PHP
June 11, 2007 1:46 PM Subscribe
How do I find all possible combinations of a multidimensional array in PHP?
posted by grrarrgh00 to Computers & Internet (13 answers total) 1 user marked this as a favorite
This is a pretty simple function that I'm sure many real developers have created in their sleep before me. Unfortunately, I can't find any working examples of their scripts to crib off of.
I'd just like to write a simple function taking a multidimensional array as an argument, and looping through all the possible unique combinations of elements in the array.
Here's a similar question
from the archives that includes links to PHP code that's apparently no longer online. Here's an answer to a similar problem
that doesn't work in PHP5. There's a solution here
that I sorta think I understand, but doesn't seem to work when I execute it. (It produces "PHP Warning: Missing argument 2 for getAllPossiblePermutations()."
Any tips? Thanks in advance!