title: PHP validation: 4 x 3 optional drop-downs
body: <p>So, I have to code an error checking solution for the following situation:</p>
  
  <ul>
  <li>User has four chances to select from three drop-down menus:
  <ul>
  <li>Drop-down 1: Up to 15 options plus a blank (zero)</li>
  <li>Drop-down 2: Up to 8 options plus a blank (zero)</li>
  <li>Drop-down 3: Always 3 options plus a blank (zero)</li>
  </ul></li>
  <li>All four are optional, but if one of the three are selected, the other two cannot be left blank</li>
  <li>The values of the drop-down options are all numbers, with (blank) being zero</li>
  <li>Drop-down 1 and Drop-down 2 cannot be used again in any of the other three groups (i.e. if the users chooses to enter all four groups, there must be 8 unique values), but the third option can be repeated in the other groups</li>
  </ul>
  
  <hr>
  
  <p>What is the most efficient way to</p>
  
  <ul>
  <li>(a) Check that if DD1 of G1 > 0, then DD2 and DD3 of G1 also > 0</li>
  <li>(b) Check that if DD1 of G1 = 0, then DD2 and DD3 of G1 also = 0</li>
  <li>(c) All combinations of drop-downs and groups of the above</li>
  <li>(d) Check I have up to 8 unique numbers, but ignoring zeroes, for the right amount of selected groups (i.e. either 2, 4, 6 or 8 - if only two groups are completed then there will be four zeroes, which is allowed).</li>
  </ul>
  
  <hr>
  
  <p>I am aware of elseif, but the only way I can think to do point (a) and (b) above is something like:</p>
  
  <pre><code>if($dd1g1&gt;0 &amp;&amp; ($dd2g1&gt;0 &amp;&amp; $dd3g1&gt;0))
  {
   echo "DD1 of G1 is not blank, and DD2 and DD3 are also not blank.";
   // allowed
  }
  else
  {
   echo "DD1 of G1 is not blank, but DD2 and DD3 are blank";
   // fail
  }
  </code></pre>
  
  <p>I would have to repeat this 3^4 (=81) times just to satisfy two rules. Is there no easier way to do this?</p>