title: Remove empty fields in an array after foreach in PHP
body: <p>I am new to PHP. This is my code from our mailing.php. When a user submits a request, there are 5-7 select-able fields and 20-25 fields that end up not being selected. The output lists all fields and values regardless of whether they are empty or have been selected. I understand I need to use either <code>unset</code> or <code>array_filter</code>, but cannot figure out how and where I need to insert into code.</p>
  
  <pre><code>if($_POST &amp;&amp; count($_POST)) {
  
      $body = '';
  
      foreach($_POST as $key=&gt;$value)
          $body .= $key . ": " . $value . "\r\n";
  
      mail("email@email.com", "Email Received at email@email.com", $body);
  </code></pre>