I have three arrays each having SimpleXML Objects in them. They are structured like so:
Array
(
[0] => SimpleXMLElement Object
(
[post_id] => 1476
[name] => Johnson Fisheries Ltd.
[owner] => Mr. John Johnson
)
)
I want to be able to compare all 3 arrays and filter out the differences so that the results have only the elements that are the same in all 3 arrays.
For example:
Array1
(
[0] => 1476
[1] => 1560
[2] => 1342
)
Array2
(
[0] => 2454
[1] => 1476
)
Array3
(
[0] => 3412
[1] => 7512
[2] => 2454
[4] => 1476
)
The resulting array would only contain [0] => 1476
What’s the best way to do this? I’ve looked for a function that will compare arrays in this way but I have had no luck. Any ideas?
Any help is very appreciated!
Loop over your first array, checking it against the 2nd and 3rd using in_array, like this: