Home > other >  Finding if a value in array exists in an second array
Finding if a value in array exists in an second array

Time:09-08

I have 2 arrays:

$selected_symptoms_array = explode(',', $symptoms);
$symptoms_array = explode(',', $disease->symptoms_id);

This is a set of IDs, like 8,9,42,68,193,209. I need to find a match if at least one value matches.

For example if ID 8 in symptoms_array

CodePudding user response:

Have a look here.
You can use array_intersect

count(array_intersect($arr1, $arr2))

If the return value of count() is higher than 0: $arr1 has at least one same value as $arr2

  • Related