title: Generating all combinations of possible clicked checkboxes to add the values
body: <p>I have to generate all possible combinations of four checkboxes where order does not matter. 
  The reason the order does not matter is because I will add up the values connected to those checkboxes.</p>
  
  <p>The array of categories is: <code>['kw1','kw2','kw3','kw4']</code></p>
  
  <p>This means that <code>kw1+kw2 = kw2+kw1</code>. So this must be seen as one combination.</p>
  
  <p>I've gotten pretty far, but I am failing to wrap my head around it.</p>
  
  <p>First of all, the user can click between 1 and 4 checkboxes, there is no fixed amount of checked checkboxes required.
  This can be translated to a for loop:</p>
  
  <pre><code>for($i=1;$i&lt;=4;$i++){
  
  }
  </code></pre>
  
  <p>When only 1 checkbox can be clicked, there are 4 possible options. When 4 checkboxes are checked, only 1 option is available. 
  When the 1st checkbox is checked, there are only 3 options left. When the 2nd checkbox is checked, only 2 options remain available. You get the drill.</p>
  
  <p>I translated this to:</p>
  
  <pre><code>for($i=1;$i&lt;=4;$i++){
      $j = 5 - $i;
      $reverse_j = 0;
      $categories = array('kw1','kw2','kw3','kw4');
      for($j;$j&gt;0;$j--){
          $reverse_j++;
          $counter = 0;
          foreach($categories as $category){
              $counter++;
              $tmp = $categories;
              if($counter &lt;= $i){
                  $result[$i][$reverse_j][] = $tmp[0];
                  unset($tmp[0]);
                  $tmp = array_values($tmp);
              }
          }
          unset($categories[0]);
          $categories = array_values($categories);
      }
  }
  </code></pre>
  
  <p>The above is one of many failed attempts to trying to generate the combinations.
  I've written out all the combinations, because it is not that hard, but I would really want to create code for it.</p>
  
  <p>The possible combinations should be:</p>
  
  <pre><code>1 click = (1), (2), (3), (4)
  2 clicks = (1-2), (1-3), (1-4), (2-3) ,(2-4), (3-4)
  3 clicks = (1-2-3), (1-2-4), (1-3-4), (2-3-4) 
  4 clicks = (1-2-3-4)
  </code></pre>
  
  <p>What am I missing? Where does my thinking go wrong?</p>