Skip to content
Advertisement

get array_intersect count without duplicates php

I have 2 arrays:

JavaScript

when i use $count = array_intersect($first, $second);, and count($count); the matches, it shows 5, resulting in 1 intersecting twice. I need to get 4, which doesn’t count duplicates.

how can I achieve that in php?

thanks in advance.

Advertisement

Answer

It’s very simple: first make sure your arrays are unique, and then apply array_intersect:

JavaScript

Repro case on 3v4l.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement