0

I have a scenario as follows where I need to check value exists in array or not using in_array

$allRecordTypes =  array('new','newly','brandnew','branded');
$tempRecordTypes = array('new','newly');
$RecordType = in_array($tempRecordTypes,$allRecordTypes);

I'm sure that the above code is not correct, but I need to check whether the $tempRecordTypes need to be checked with $allRecordTypes.

John Conde
  • 217,595
  • 99
  • 455
  • 496
Kiran Kumar
  • 181
  • 1
  • 4
  • 13
  • Possible duplicate of [in\_array multiple values](http://stackoverflow.com/questions/7542694/in-array-multiple-values) – T.Todua Aug 27 '16 at 08:57

1 Answers1

4

You need to use array_intersect() to see what values are in both arrays. in_array() checks to see if one value exists in an array so that won't work for you (unless you use a loop to iterate through your $tempRecordTypes array and compare it to the $allRecordTypes array).

$RecordType = array_intersect($tempRecordTypes,$allRecordTypes);
John Conde
  • 217,595
  • 99
  • 455
  • 496