Reputation:
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
Upvotes: 1
Views: 50
Reputation: 50874
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
Upvotes: 1