I have an array like this.
$flds = array("fn", "ln", "em");
I have another associative array like this. this is dynamically returned from JSON POST.
$ret = array("fn" => "xyz", "ln" => "abc", "em" => "s.2", "another" => "123")
I want to search if the first array is existing in the 2nd array.
I did this:
if ( in_array( $flds, array_keys($ret)))
echo "exists";
else
echo "does not";
It always returns “does not”. When I print, $flds and array_keys($ret), both look exactly same.
Anything wrong here?
That code is looking for the entire $flds array to be a value in $ret;
You’ll probably want to use array_intersect() and then check the length of the result.