1

I am trying to check if value of an array $spam is present in array $get_mail. I have following code, but it doesnt seem to work or I dont understand it properly.

$spam_exists = !array_diff($spam, $get_mail);

if ($spam_exists !== FALSE) { ... }

Any idea why this doesnt work? Thank you for any reply.

0

1 Answer 1

1

Use the array_intersect function.

$result = array_intersect($spam, $get_mail);

Which will return the values in both arrays as an array, or an empty array if there are no shared results.

So rather than using !array_diff($X,$Y) you could use !empty(array_intersect($X,$Y)) or simply if(array_intersect($X,$Y))

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.