我目前PHP Catchable fatal error: Argument 2 passed to NUI::recArrInterKey() must be an array, string given
在尝试递归地与多维数组(灰/白名单)相交时收到错误消息。
$foo['contact']['im']['provider']
由于某种我无法弄清楚的原因,它似乎在该部分绊倒?
这是我正在使用的示例白名单数组 ($array2)
Array
(
[location] => false
[network_name] => false
[interests] => false
[last_name] => false
[url] => false
[significant_other] => false
[network_domains] => false
[contact] => Array
(
[im] => Array
(
[provider] => false
)
[email_addresses] => false
)
)
以及方法
/**
* Recursive array intersect key
*/
private static function recArrInterKey(array $array1, array $array2)
{
$array1 = array_intersect_key($array1, $array2);
foreach ($array1 as $key => &$value)
{
if (is_array($value))
{
$value = self::recArrInterKey($value, $array2[$key]);
}
}
return $array1;
}
可以说这是$array1
Array
(
[location] => Seattle
[occupation] => Developer
[network_name] => foo.network
[network_region] => foo.region
[interests] => coding
[last_name] => daniel
[url] => false
[id] => 4665228
[significant_other] => some girl
[network_domains] => false
[contact] => Array
(
[im] => Array
(
[provider] => aol
)
[phone] => Array
(
[provider] => at&t
)
[email_addresses] => dont@mail.me
)
)
我期待这是一个回报
Array
(
[location] => Seattle
[occupation] => Developer
[network_name] => foo.network
[interests] => coding
[last_name] => daniel
[url] => false
[significant_other] => some girl
[network_domains] => false
[contact] => Array
(
[im] => Array
(
[provider] => aol
)
[email_addresses] => dont@mail.me
)
)