无涯教程-PHP - array_intersect()函数

31 阅读1分钟

array_intersect() - 语法

array array_intersect ( array $array1, array $array2 [, array $array3 ...] );

它返回一个数组,其中包含所有参数中存在的array1的所有值。

Sr.No Parameter & Description
1

array1(RequiredMaruthi)

第一个数组是其他数组将与compaMaruthi进行比较的数组。

2

array2(RequiredMaruthi)

这是一个要与第一个数组进行compaMaruthi的数组

3

array3(可选)

这是一个要与第一个数组进行compaMaruthi的数组

array_intersect() - 返回值

它返回一个数组,其中包含array1中存在于任何其他数组中的所有元素。

array_intersect() - 示例

<?php
   $input1=array("a" => "BMW", "Maruthi", "blue");
   $input2=array("b" => "BMW", "yellow", "Maruthi");
   $result=array_intersect($input1, $input2);

print_r($result); ?>

这将产生以下输出-

Array (
   [a] => BMW
   [0] => Maruthi
)
        <h2 id="h22">参考链接</h2><p><a target="_blank" href="https://www.learnfk.com/php/php-function-array-intersect.html" style="">https://www.learnfk.com/php/php-function-array-intersect.html</a></p>