title: List all combinations of option strings while following order of supplied array and rules of specific options - php
body: <p>I am working on a project where a company sells a multitude of valves with a vast array of variations and need to build a site map with links to every valve data as the current navigation does not use conventional links but codes built via a user interacting with the many options on the page.  I have been able to generate everything up until the options which begin to get very tricky because of the vast array of combinations of these options there are and the rules that they follow.</p>
  
  <p>I am attempting to build every option string combinations with the rules you can find below.</p>
  
  <p>Given the array of option codes (at the end of the post) I must generate a list of all possible combinations but they must follow the order that they are presented and follow the rules given by the row_mod. For example when the option_code of O is in the combinations the option_code of ON and OP are not allowed to be in the combination.</p>
  
  <p>The only row_mod info that needs to be followed currently when building these strings is the "naWithOp##" as that refers to another option that is not allowed to be with it.</p>
  
  <p>Some of the possible combinations that would need to come out of the script would be:</p>
  
  <ol>
  <li>OTKZ</li>
  <li>OTK</li>
  <li>OT</li>
  <li>OTOSZ</li>
  <li>OTOS</li>
  <li>O</li>
  <li>OL</li>
  <li>OLKZ</li>
  <li>OLK</li>
  </ol>
  
  <p>I know this isn't even close to the exhaustive list of how many are actually possible but I can't figure out how to generate all the possible combinations.</p>
  
  <hr>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [option_code] =&gt; O
              [row_mod] =&gt; allowAll naWithOpON naWithOpOP
          )
  
      [1] =&gt; Array
          (
              [option_code] =&gt; ON
              [row_mod] =&gt; allowAll naWithOpO naWithOpOP
          )
  
      [2] =&gt; Array
          (
              [option_code] =&gt; OP
              [row_mod] =&gt; allowAll naWithOpO naWithOpON
          )
  
      [3] =&gt; Array
          (
              [option_code] =&gt; T
              [row_mod] =&gt; allowAll naWithOpL
          )
  
      [4] =&gt; Array
          (
              [option_code] =&gt; L
              [row_mod] =&gt; allowAll naWithOpT naWithCoilX
          )
  
      [5] =&gt; Array
          (
              [option_code] =&gt; K
              [row_mod] =&gt; allow2 allow3 allow3P naWithOpOS
          )
  
      [6] =&gt; Array
          (
              [option_code] =&gt; OS
              [row_mod] =&gt; allow2 allow3 allow3P naWithOpK
          )
  
      [7] =&gt; Array
          (
              [option_code] =&gt; Z
              [row_mod] =&gt; allowAll naWithPreB
          )
  
  )
  </code></pre>
  
  <p>Basically I must start on the first option code and iterate down the list starting with the first given option 'O' then go to the next option 'ON' and check whether its valid and if it is then add it to the current combination. And so on and so forth building allowed combinations and storing them to an array. </p>
  
  <p>User Interface example:
  I created a jsfiddle that is interactive in the way that the options work together. Found <a href="http://jsfiddle.net/kpwn243/5dajxv5t/" rel="nofollow">here</a></p>
  
  <p>I'm not sure what approach I should be taking but I have tried using recursive algorithms to no avail.</p>