title: foreach loop multidimensional array but only loop through array elements with specific key
body: <p>I am creating following array that contains all products and all their categories:</p>
  
  <pre><code>$result = $wpdb-&gt;get_results("SELECT product_nr, category FROM erp_product_categories",ARRAY_A);
  $product_categories = array();
    foreach($result as $row){
      $product_categories[$row["product_nr"]][] = $row["category"];
    }
  </code></pre>
  
  <p>(product_nr is an integer and category is a string)</p>
  
  <p>Then i want to check if one of the categories of a product matches with an other variable and return true if thats the case:</p>
  
  <pre><code>foreach($product_categories[$ean] as $product_categorie) {
      $manages_post = in_array( $product_categorie, $this-&gt;term_link_conditions );
  
      if($manages_post == true){
          break;
      }
  }
  return $manages_post;
  </code></pre>
  
  <p>But I am getting the error</p>
  
  <blockquote>
    <p>Invalid argument supplied for foreach()</p>
  </blockquote>
  
  <p>is it not possible to loop only through elements of an array with a specific key?</p>
  
  <p>Edit:
  The array looks like this</p>
  
  <pre><code>Array
  (
      [10001] =&gt; Array       //product_nr
      (
          [0] =&gt; 1           //category
          [1] =&gt; 4           //category
      )
  
      [10002] =&gt; Array
      (
          [0] =&gt; 1
          [1] =&gt; 20
      )
      //...
  )
  </code></pre>