PHP Recursive Array Intersect Key Tripping over string value <p>I'm currently receiving an error <code>PHP Catchable fatal error: Argument 2 passed to NUI::recArrInterKey() must be an array, string given</code> when trying to recursively intersect a multidimensional array (grey/white list).</p> <p>It seems to be tripping on the <code>$foo['contact']['im']['provider']</code> section for some reason that I can't figure out?</p> <p>Here's an example whitelist array ($array2) that I am using</p> <pre><code>Array ( [location] =&gt; false [network_name] =&gt; false [interests] =&gt; false [last_name] =&gt; false [url] =&gt; false [significant_other] =&gt; false [network_domains] =&gt; false [contact] =&gt; Array ( [im] =&gt; Array ( [provider] =&gt; false ) [email_addresses] =&gt; false ) ) </code></pre> <p>And the method</p> <pre><code>/** * Recursive array intersect key */ private static function recArrInterKey(array $array1, array $array2) { $array1 = array_intersect_key($array1, $array2); foreach ($array1 as $key =&gt; &amp;$value) { if (is_array($value)) { $value = self::recArrInterKey($value, $array2[$key]); } } return $array1; } </code></pre> <p>lets say that this is <code>$array1</code></p> <pre><code>Array ( [location] =&gt; Seattle [occupation] =&gt; Developer [network_name] =&gt; foo.network [network_region] =&gt; foo.region [interests] =&gt; coding [last_name] =&gt; daniel [url] =&gt; false [id] =&gt; 4665228 [significant_other] =&gt; some girl [network_domains] =&gt; false [contact] =&gt; Array ( [im] =&gt; Array ( [provider] =&gt; aol ) [phone] =&gt; Array ( [provider] =&gt; at&amp;t ) [email_addresses] =&gt; dont@mail.me ) ) </code></pre> <p>I am expecting this as a return</p> <pre><code>Array ( [location] =&gt; Seattle [occupation] =&gt; Developer [network_name] =&gt; foo.network [interests] =&gt; coding [last_name] =&gt; daniel [url] =&gt; false [significant_other] =&gt; some girl [network_domains] =&gt; false [contact] =&gt; Array ( [im] =&gt; Array ( [provider] =&gt; aol ) [email_addresses] =&gt; dont@mail.me ) ) </code></pre>