1

I have two arrays like given below from these two arrays I am getting missing element that is also given below:

$news=[1,2,3,4,5,6,7];

$new=[1,2,4,6,7];

$missing=[3,5];

I want when I have two values or multi-values in that case if the condition should work and for another value else part to be executed

if(in_array($news,$missing))
{
echo "ok";
}
else
{
echo "no";
}

case would be :[3] ,[5] and [3,5];

I want if array value =3 output should be no if value=5 output should be=no if both then also output should be no but when value is different like [4] or [4,6] output would be ok;

can anyone please help me related this I am stuck here. Or is there any way to solve this kind of problems
Shruti
  • 149
  • 1
  • 9

1 Answers1

2

You can use array_intersect()

count(array_intersect($news,$missing))

If count > 0 means there is atleast one element in both arrays, so answer will be no. It count = 0, means both arrays have different values, so answer will be ok.