UK ['dɪf] US ['dɪf]
abbr.differential differential(of);difference different;differ different;differentiator differentiator
php array_diff() function syntax
Function:Compare the key values of two arrays and return the difference
Syntax: array_diff(array1,array2,array3...)
Parameters:
Description | |
Required. The first array to compare with other arrays. | |
Required. The array to compare to the first array. | |
Optional. Additional array to compare with the first array. |
#Description: Returns the difference array of two arrays. This array contains all keys that are in the array being compared, but are not in any of the other parameter arrays. In the returned array, the key names remain unchanged.
php array_diff() function example
<?php $class1 = array("西门"=>"55","灭绝"=>"44","无忌"=>"22"); $class2 = array("西门"=>"54","灭绝"=>"44","无忌"=>"25"); print_r(array_diff($class1,$class2 )); //返回两个数组中不一样的元素 ?>
Run instance»
Click the "Run instance" button to view the online instance
Output:
Array ( [西门] => 55 [无忌] => 22 )
<?php $per1=array("a"=>"灭绝师太","b"=>"欧阳克","c"=>"西门大官人","d"=>"韦小宝"); $per2=array("e"=>"Peter","f"=>"慕容复","g"=>"陈近南"); $per3=array("a"=>"灭绝师太","b"=>"欧阳克","h"=>"王重阳"); $result=array_diff($per1,$per2,$per3); print_r($result); ?>
Run Instance»
Click the "Run Instance" button to view the online instance
Output:
Array ( [c] => 西门大官人 [d] => 韦小宝 )