php - unknow ERROR (in_array() expects parameter 2 to be array, string given)
Get the solution ↓↓↓Solution:
Just like the comments above, if$friends
is indeed just a flat array, just usein_array
alone. No need forforeach
. What happens is, you're applyingin_array
of each string which doesn't make sense. You applyin_array
to the whole array of strings:
function isFriend($user, $friend) {
return in_array($friend, getUsersFriends($user));
}
Take note thatSanoj != sanoj
. It might be better to change all the caps of the collection of friends to compare against thestrtolower
ed$friend
:
Idea:
function isFriend($user, $friend) {
return in_array(strtolower($friend), array_map('strtolower', getUsersFriends($user)));
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: please make sure the php redis extension is installed and enabled.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.