title: Laravel | Filter null values from an associative array
body: <p>I have an associative array like this:</p>
  <pre><code> $myarray = array(
                  'key1' =&gt; 'value1'
                  'key2' =&gt; 'value1','value2','value3', null ,'value4'
                   null
                  'key4' =&gt; null ,'value2','value3', null
                  'key5'
                   null
                  );
  </code></pre>
  <p>I want to remove the null values and I tried this:</p>
  <pre><code>$collection = collect($myarray);
  
              $filtered = $collection-&gt;filter(function ($value, $key) {
                  return $value != null;
              });
  </code></pre>
  <p>The result is this:</p>
  <pre><code>     $myarray = array(
                  'key1' =&gt; 'value1'
                  'key2' =&gt; 'value1','value2','value3', null ,'value4'
                  'key4' =&gt; null ,'value2','value3', null
                  'key5'
                  );
  </code></pre>
  <p>But my desired result is like this:</p>
  <pre><code>     $myarray = array(
                  'key1' =&gt; 'value1'
                  'key2' =&gt; 'value1','value2','value3','value4'
                   null
                  'key4' =&gt; 'value2','value3'
                  'key5'
                   null
                  );
  </code></pre>
  <p>How can I do this?</p>
  <p>PS: I'm using Laravel 5.4.36</p>