title: php how to insert an element into array if is not null
body: <p>I need to fill an array with a list of elements only if value is not null.
  Is there a way to skip the array filling if value to be appended is null?</p>
  
  <p>As example:</p>
  
  <pre><code>$list = array();
  for ($i = 1; $i &lt;= 10; $i++) {
      $modulo = ($i % 2);
      if ($modulo) $list[] = $i;
  }
  </code></pre>
  
  <p>Is there a way to write the two statement in the loop into an unique one <strong>without using $modulo variable</strong>?</p>
  
  <p>something like...</p>
  
  <pre><code>$list = array();
  for ($i = 1; $i &lt;= 10; $i++) {
      $list[] = ($i % 2);
  }
  </code></pre>
  
  <p>The expected behavior is that $list array has to contain 1,3,5,7,9...</p>
  
  <p><em>This is not the real example as the ($i % 2) has to be replaced with a complex function applied on an array of 380k elements and may return something or null. And I want to exclude null values.</em></p>