all
I have a bundle of data like 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
then I separate these data into 2 groups which is
$groupA = range(1, 5)
$groupB = range(6, 10)
For instance, I have $data = array(1, 4) and it will return this belong to Group A. Likewise,
$data = array(7,8), it will return to me Group B.
So how can I write a script to let $data = array(1, 4, 6, 7) return me Group A and Group B?
Thank you
You may want to use
array_intersect:Note that an empty array evaluates to
falsewhile one with at least one element evaluates totrue.Warning: If you have to work with a lot of groups with many elements you may want to use a manual approach and stop at the first common element found.
array_intersectfinds all the common elements and you don’t really need that.