Skip to content
Advertisement

output common int using array_search

I am trying to create a function that will output the smallest common int or return false if there is not one in three arrays. The arrays are sorted ascending and I want to do with array_search.

When I execute this code it returns nothing and I don’t know why it should echo 5 I think

JavaScript

Advertisement

Answer

Here is a different method of doing it.

First I find the lowest number that it could possibly be $min.

Then I loop the $a array and skip until I find at least $min.
if array search of $b and $c is not false then we found the lowest possible match and break the code.

JavaScript

But the simplest code is probably array_intersect. But OP asked for array_search…

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement