title: How to filter an associative arrays using keys of an indexed array in PHP?
body: <p>The callback function in <a href="http://php.net/manual/en/function.array-filter.php" rel="noreferrer"><code>array_filter()</code></a> only passes in the array's values, not the keys.</p>
  <p>If I have:</p>
  <pre><code>$my_array = array(&quot;foo&quot; =&gt; 1, &quot;hello&quot; =&gt; &quot;world&quot;);
  
  $allowed = array(&quot;foo&quot;, &quot;bar&quot;);
  </code></pre>
  <p>What's the best way to delete all keys in <code>$my_array</code> that are not in the <code>$allowed</code> array?</p>
  <p>Desired output:</p>
  <pre><code>$my_array = array(&quot;foo&quot; =&gt; 1);
  </code></pre>