title: How to remove empty values from multidimensional array in PHP?
body: <p>I've been looking a lot of answers, but none of them are working for me.</p>
  
  <p>This is the data assigned to my <code>$quantities</code> array:</p>
  
  <pre><code>Array(
      [10] =&gt; Array([25.00] =&gt; 1)
      [9] =&gt; Array([30.00] =&gt; 3)
      [8] =&gt; Array([30.00] =&gt; 4)
      [12] =&gt; Array([35.00] =&gt; )
      [1] =&gt; Array([30.00] =&gt; )
      [2] =&gt; Array([30.00] =&gt; )
  )
  </code></pre>
  
  <p>I'm looking for a way to remove the subarrays with empty values like <code>[12]</code> <code>[1]</code> and <code>[2]</code> while keeping everything else.</p>
  
  <p>The desired result:</p>
  
  <pre><code>Array(
      [10] =&gt; Array([25.00] =&gt; 1)
      [9] =&gt; Array([30.00] =&gt; 3)
      [8] =&gt; Array([30.00] =&gt; 4)
  )
  </code></pre>
  
  <p>I tried a lot of the functions on the official php docs and none of them worked.</p>
  
  <p>I've used this one:</p>
  
  <pre><code>function array_filter_recursive($array, $callback = null) {
      foreach ($array as $key =&gt; &amp; $value) {
          if (is_array($value)) {
              $value = array_filter_recursive($value, $callback);
          } else {
              if ( ! is_null($callback)) {
                  if ( ! $callback($value)) {
                      unset($array[$key]);
                  }
              } else {
                  if ( ! (bool) $value) {
                      unset($array[$key]);
                  }
              }
          }
      }
      unset($value);
      return $array;
  }
  </code></pre>
  
  <p>But it only removes the element in the subarrays; I need the subarrays to be removed entirely.</p>
  
  <p>I don't want this:</p>
  
  <pre><code>Array(
      [10] =&gt; Array([25.00] =&gt; 1)
      [9] =&gt; Array([30.00] =&gt; 3)
      [8] =&gt; Array([30.00] =&gt; 4)
      [12] =&gt; Array()
      [1] =&gt; Array()
      [2] =&gt; Array()
  )
  </code></pre>