title: Filtering email addresses in an array -php
body: <p>I have a php array containing email addresses as array(email_address1 => name1, email2 => name2) format.</p>
  
  <p>I need to check that emails are valid and I can <code>foreach</code> and </p>
  
  <pre><code>foreach($arr as $email =&gt; $name) { 
     $new = array();
     if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
     $new[$email] = $name;
    }
  return $new;
  }
  </code></pre>
  
  <p>Can I achieve the above using array_filter? what would be the syntax??</p>
  
  <pre><code>array_filter($emails_arr, 'filter_var') ?? how about FILTER_VALIDATE_EMAIL parameter?
  </code></pre>
  
  <p>thanks.</p>