array_diff
PHP array_diff()函数 (PHP array_diff() Function)
array_diff() function is an array function in PHP, it is used to find the differences of two or more arrays.
array_diff()函数是PHP中的一个数组函数,用于查找两个或多个数组的差异。
It compares the values of given arrays and returns the values which are not common in the arrays.
它比较给定数组的值,并返回数组中不常见的值。
It compares values of the first array with the second array and returns the values which are not present in the second array.
它将第一数组的值与第二数组的值进行比较,并返回第二数组中不存在的值。
Syntax:
句法:
array_diff(array1, array2, ...) : array
Here, array1, array2 are the input arrays, two array parameters are required. We can also provide more arrays to compare.
在这里, array1 , array2是输入数组,需要两个数组参数。 我们还可以提供更多数组进行比较。
Examples:
例子:
Input:
$arr1 = array("101" => "Amit", "102" => "Abhishek", "103" => "Prem");
$arr2 = array("101" => "Amit", "102" => "Abhishek");
Function call:
array_diff($arr1, $arr2);
Output:
Array
(
[103] => Prem
)
PHP code:
PHP代码:
<?php
$arr1 = array("101" => "Amit", "102" => "Abhishek", "103" => "Prem");
$arr2 = array("101" => "Amit", "102" => "Abhishek");
//finding & printing arrays
$ans = array_diff($arr1, $arr2);
print_r ($ans);
?>
Output
输出量
Array
(
[103] => Prem
)
<?php
$arr1 = array(10, 20, 30, 40, 50);
$arr2 = array(10, 20, 60, 70, 70);
print_r (array_diff($arr1, $arr2));
?>
Output
输出量
(
[2] => 30
[3] => 40
[4] => 50
)
翻译自: https://www.includehelp.com/php/array_diff-function-with-example.aspx
array_diff