Imgagining i have two array
arr[]={"red","blue","green"}
arr2[]={"red","violet","black"}
How will i compare the two array to get the result that i common to both of the arrays..
For this the result is red…
How wil i do this in php(simple means)…Can anyone suggest???
To put it quick:
http://php.net/manual/en/function.array-intersect.php
The function takes multiple array and returns an array with ONLY elements that are in every single array.
Multidimensional
This snippet takes all the multidimensional arrays and UNIONS the array together before INTERSECTING the results:
($multi1[0] U $multi1[1] U ... U $multi1[n]) INTERSECT ($multi2[0] U $multi2[1] U ... U $multi2[m]):This snippet takes all the multidimensional arrays and UNIONS the array together before INTERSECTING the results:
($multi1[0] INTERSECT $multi1[1] INTERSECT ... INTERSECT $multi1[n]) INTERSECT ($multi2[0] INTERSECT $multi2[1] INTERSECT ... INTERSECT $multi2[m]):EDIT – Recursion
To make it simpler to read i made it recursive for the INTERSECT all case:
used like this:
notice the dimension 3 since the array we are passing in is:
The result should be:
array('3')