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
)
)