如何检查数组键值是否存在于另一个数组中

时间:2015-11-11 08:55:37

标签: php arrays

我有两个

数组
    $key = array(
                "site_url" => "Site URL",
                "current_date" => "Current Date",
                "user_name" => "User name", 
                "name" => "Name of the user",
                "password" => "Password of user",
                "user_email"  => "Email address of new user"
            );
   $tmpl_name = array ("name","url","current_date","email");

我想检查第一个数组的键值中是否存在第二个数组值。如果没有,则显示哪一个与第一个数组不同。

1 个答案:

答案 0 :(得分:0)

$response->DoExpressCheckoutPaymentResponseDetails->PaymentInfo->SellerDetails->PayPalAccountID array_diff相结合即可。试试这个:

array_keys

输出为:

$missing    = array_diff($tmpl_name, array_keys($key));

或者你可以交换它们:

array(2) {
    [1] = string(3) "url"
    [3] = string(5) "email"
}

获取第一个数组中不在第二个值中的键。

$missing    = array_diff(array_keys($key), $tmpl_name);