| This article describes how to find the correlated array difference set in the php array, mainly the usage of the php array function array_diff_assoc. For more information, see. In php, evaluate the difference set of the correlated array. The array_diff_assoc () function is basically the same as the array_diff () function, except that the array key is also considered during comparison. Therefore, only key/value pairs that appear in the first array instead of other input arrays are returned to the result array. The format is as follows: array array_diff_assoc (array array1, array array2 [, arrayN…]) In this example, only [yellow] => Banana is returned, because this special key/value pair exists in $ fruit1, and does not exist in $ fruit2 or $ fruit3.
"Apple", "yellow" => "Banana", "orange" => "Orange"); $ fruit2 = array ("yellow" => "Pear ", "red" => "Apple", "purple" => "Grape"); $ fruit3 = array ("green" => "Watermelon ", "orange" => "Orange", "red" => "Apple"); $ intersection = array_diff_assoc ($ fruit1, $ fruit2, $ fruit3); print_r ($ intersection ); // output // Array ([yellow] => Banana)?>Note: When traversing an array in php, you usually need to traverse the array and obtain each key or value (or simultaneously obtain the key and value). PHP provides some functions to meet your needs. Many functions can complete two tasks, not only to obtain the key or value of the current pointer position, but also to move the pointer to the next appropriate position. |