The first array is called $related_docs and the second on is $all_docs. I’m trying to match the “1” value in the first array with the “1” value in the second array.
Array
(
[0] => 1
)
Array
(
[0] => Array
(
[id] => 1
[type_name] => bla1
)
[1] => Array
(
[id] => 2
[type_name] => bla2
)
[2] => Array
(
[id] => 3
[type_name] => bla3
)
)
I’m trying to see if any values from the first array occur in the second array, which it does, but the script prints out nothing but “no”. Why is that? I’ve tried changing $all_docs in the if() statement to $a but that makes no difference.
foreach($all_docs as $a)
{
if( in_array($related_docs, $all_docs) )
{
print "yes";
}
else print "no";
}
Do I need to search recursively in the second array?
You are trying to do a recursive search, which
in_array()can’t do. It can only very primitively match against the first level of the array you search in.Maybe this implementation of a recursive in_array() works for what you need.
Alternatively, use something along the lines of: