-6

Q1:如何显示匹配值?

数组 1:

Array ( [0] => 9 [1] => 10 [2] => 11 [3] => 12 [4] => 13 [5] => 14 [6] => 15 [7] => 16 ) 

数组 2:

Array ( [0] => 8 [1] => 9 [2] => 10 [3] => 11 [4] => 12 [5] => 13 [6] => 14 [7] => 15 [8] => 16 [9] => 17 [10] => 18 [11] => 19 [12] => 20 [13] => 21 [14] => 22 [15] => 23 )

输出:

09-16

如何在数组中显示匹配的第一个值和最后一个值

4

3 回答 3

1
$matching = array_intersect($array1, $array2);
print_r($matching);

array_intersect

于 2013-06-12T10:44:45.427 回答
0

获取数组中的匹配值

用于array_intersect()返回匹配值。

在此处查看文档

例子:

// Get the matching values
$matching_values = array_intersect($array1,$array2);

// This will print the matching values in the arrays
print_r($matching_values);

获取数组中不匹配的值

用于array_diff()返回数组的差异。

在此处查看文档

例子:

// Get the non-matching values
$differences = array_diff($array1,$array2);

// This will print the differences in the arrays
print_r($differences);
于 2013-06-12T10:45:22.960 回答
0

试试喜欢

$arr = array_intersect(array1,array2);
print_r($arr);
于 2013-06-12T10:45:31.610 回答