1

Having two arrays of authRoom and partiRoom with one same value inside them. Want to find that same value if it was matched

Found array_search function that work only with single variable

$authRoom = [8, 7, 1, 22, 13, 18, 10];
$partiRoom= [3, 6, 5, 9, 8];

I want the output to be 8 which is the same value of these two arrays

1 Answer 1

1

You can use array_intersect which will give you an array of the same values in both $authRoom and $partiRoom like so:

$authRoom = [8, 7, 1, 22, 13, 18, 10];
$partiRoom = [3, 6, 5, 9, 8];

$res = array_intersect($authRoom, $partiRoom);
print_r($res); // [8]

If you want to get the value 8 outside of the array, you can simply access the first value using index 0:

$res = array_intersect($authRoom, $partiRoom)[0];
echo $res; // 8
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.