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.

1

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.