title: Iterating over multidimensional array where some arrays might have no elements
body: <p>I have a $products array like this:</p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [0] =&gt; 1001
              [1] =&gt; 1002
          )
  
      [1] =&gt; 
      [2] =&gt; 
      [3] =&gt; 
      [4] =&gt; 
      [5] =&gt; 
      [6] =&gt; 
      [7] =&gt; 
  )
  </code></pre>
  
  <p>I want to loop through it and create a one-level array comprised only of the non-empty array data like this:</p>
  
  <pre><code>$newArr = [
      [0] =&gt; 1001,
      [1] =&gt; 1002
  ]
  </code></pre>
  
  <p>My foreach loop that I thought would work throws an error (<code>'Invalid argument supplied for foreach()'</code>).</p>
  
  <p>The foreach loop looks like this:</p>
  
  <pre><code>$idArr = [];
  foreach($products as $value) {
      foreach ($value as $id) {
          echo $id . '&lt;br&gt;';
          $idArr[] = $id;
      }
  }
  </code></pre>
  
  <p>The two values echo suggesting the code is correct, but it's not. I am unable to store the iterated $id value into <code>$idArr[]</code>.</p>
  
  <p>If anyone can spot my error or errors, I would appreciate it.</p>
  
  <p>Thanks!</p>