如何在php中获取匹配的数组值

如何在php中获取匹配的数组值,php,Php,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]

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

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

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

获取数组中的匹配值 使用
array\u intersect()
返回匹配值

见文件

例如:

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

// This will print the matching values in the arrays
print_r($matching_values);
// Get the non-matching values
$differences = array_diff($array1,$array2);

// This will print the differences in the arrays
print_r($differences);
获取数组中不匹配的值 使用
array_diff()
返回数组之间的差异

见文件

例如:

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

// This will print the matching values in the arrays
print_r($matching_values);
// Get the non-matching values
$differences = array_diff($array1,$array2);

// This will print the differences in the arrays
print_r($differences);
试着

$arr = array_intersect(array1,array2);
print_r($arr);

我已经格式化了代码,这样你至少可以阅读它。@MattHarrison这几乎不是代码:-PDid你甚至试着用谷歌搜索它
array\u intersect
是第一个以您的确切问题作为查询的结果@BenCarey好吧,你知道……我只是为了检查。如何在匹配数组中获取第一个值和最后一个值,然后如何从匹配数组中仅显示该值09-16