..


Sponsored Links

array_diff_assoc

Array_diff_assoc function compares two or more arrays and returns a new array with the keys and values ​​of the first array that are not found in any other arrays used in the comparison.

The function in question admits a minimum of two parameters:

  • array1 - (mandatory) The first array is the touchstone for the other arrays;
  • array2 - (required) An array to be compared with the first array;
  • arrayN - (optional) Other arrays to be compared with the first array;
Note well that in the comparison are used both keys and values.

Here's an example:





 $ A1 = array (0 => "Cat", 1 => "Dog", 2 => "Rat");







 $ A2 = array (0 => "Chicken", 1 => "Rat", 2 => "Dog");







 $ A3 = array (0 => "Rat", 1 => "Dog", 2 => "Cat");







 print_r (array_diff_assoc ($ a1, $ a2, $ a3));



The output of the code above will be:
 



 Array (



  



 [0] => Cat



  



 [2] => Rat







 )

 
The second array, as you can see, has no key / value pair in common with the first and the third array, however, the pair shares 1 => "Dog".

In the same category ...
E-Learning
Linux (Course) Linux (Course)
Complete guide to open-source system. From 49 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Sponsored Links