intersect函数_PHP array_intersect_key()函数与示例

intersect函数

PHP array_intersect_key()函数 (PHP array_intersect_key() Function)

array_intersect_key() function is used to find the matched elements from two or more elements (compares keys). Function “array_intersect_key()” compares the keys of the first array with the other arrays and returns matched elements based on the keys of the first array.

array_intersect_key()函数用于从两个或多个元素(比较键)中查找匹配的元素。 函数“ array_intersect_key()”将第一个数组的键与其他数组进行比较,并根据第一个数组的键返回匹配的元素。

Syntax:

句法:

    array_intersect_key(array1, array2, [array3,...]);

Here, array1, array2 are the input arrays other arrays are an optional.

在这里, array1 , array2是输入数组,其他数组是可选的。

Examples:

例子:

    Input:
    $arr1 = array("name" => "Prem", "age" => 28, "city" => "Gwalior");
    $arr2 = array("name" => "Amit", "age" => 23, "gender" => "Male");

    Function calling: 
    array_intersect_key($arr1, $arr2);

    Output:
    Array
    (
        [name] => Prem
        [age] => 28
    )

PHP code:

PHP代码:

<?php
    
    $arr1 = array("name" => "Prem", "age" => 28, "city" => "Gwalior");
    $arr2 = array("name" => "Amit", "age" => 23, "gender" => "Male");
    
    //finding matched elements
    $ans = array_intersect_key($arr1, $arr2);
    
    print_r ($ans);
?>

Output

输出量

Array
(
    [name] => Prem
    [age] => 28
)


翻译自: https://www.includehelp.com/php/array_intersect_key-function-with-example.aspx

intersect函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值