title: Comparing Array of array with an array PHP
body: <p>I'm working on a custom shopping cart variation code and want to check if the selected option array is available out of a main array of all the products options.</p>
  
  <p>For example consider the following as my main array where c1, c2 are the option categories (size, colour, etc) and the value is the id of the option in that category. </p>
  
  <pre><code>$optionsarray =  Array
  (
  
      [0] =&gt; Array
          (
              [c1] =&gt; 70
              [c2] =&gt; 79
          )
  
      [1] =&gt; Array
          (
              [c1] =&gt; 71
              [c2] =&gt; 79
          )
  
      [2] =&gt; Array
          (
              [c1] =&gt; 71
              [c2] =&gt; 80
          )
  
      [3] =&gt; Array
          (
             [c1] =&gt; 70
             [c2] =&gt; 62
          )
  
      [4] =&gt; Array
          (
              [c1] =&gt; 71
              [c2] =&gt; 62
          )
  
  );
  </code></pre>
  
  <p>I want to be able to check if different values exist or not
  So if my <code>$selected_array</code>  to test is</p>
  
  <pre><code>$selected_array = Array
          (
              [c1] =&gt; 70
          )
  </code></pre>
  
  <p>I'd like to know that </p>
  
  <pre><code> [2] =&gt; Array
          (
              [c2] =&gt; 80
          )
  </code></pre>
  
  <p>from my <code>$optionsarray</code> is the only one that has no match for [c2] so I can disable that option on the front end.</p>
  
  <p>The closest I've come to getting this to work is to do the opposite and find the "allowed" matches using the following function (<code>$the_selected_cat</code> in the following example is 1 coming from the front end) </p>
  
  <pre><code>$filteredoptionsarray = array();
  $fo = 0;
  
  foreach ($optionsarray as $option) {
      $fo ++;
      $catvar = "";
      $results = array_diff_assoc($option, $selected_array);
      $catvar = 'c' . $the_selected_cat;
      if (!$results[$catvar]) {
          foreach ($results as $result =&gt; $value) {
              $filteredoptionsarray[] = (array("cat" =&gt; $result, "id" =&gt; $value));
          }
      }
  }  
  </code></pre>
  
  <p>This gives me the id's that match [c1] => 70 but what I really need is a different function or another step to get the opposite and to spit out the id of what is not available. In this example [c2] =>80</p>
  
  <p>I've attempted some functions with <code>array_intersect_assoc</code> to no avail.</p>
  
  <p>In theory I'm trying to keep this as dynamic as possible so there may be 1, 2, 3 etc option categories.</p>
  
  <p>Any push in the right direction would be greatly appreciated.</p>
  
  <p>&lt;=============== EDIT ===============></p>
  
  <p>Could be pretty specific to my application but this does the trick now </p>
  
  <pre><code>$the_selected_term = 70;
  $the_selected_cat = 1
  //above two vars coming from the front-end
  
  $allowed = array();
  $disallowed = array();
  
  foreach ( $optionsarray as $option =&gt; $value ) {
  
    if( $value['c'.$the_selected_cat] == $the_selected_term ){
  
         for ( $cc = 1; $cc &lt;= $count_cats; $cc++ ) {
              if($cc != $the_selected_cat){
                      $allowed[] = "c".$cc."-".$value['c'.$cc];
              }
            }
  
      } else {
  
          for ( $cc = 1; $cc &lt;= $count_cats; $cc++ ) {
              if($cc != $the_selected_cat){
                       $disallowed[] = "c".$cc."-".$value['c'.$cc];
                       }
            }
  
      }
  }
  
  $disabled = array();
  $results=array_diff($disallowed,$allowed);
  $results = array_unique($results);
  </code></pre>