unknow ERROR (in_array() expects parameter 2 to be array, string given)

sanoj lawrence

am using following function to state friend function between two user but i get following error

Warning: in_array() expects parameter 2 to be array, string given in C:\Users\sanoj\Documents\NetBeansProjects\PDO friends 2\userData.php on line 60

line 60 is this if (in_array($friend, $f)) { and function is bellow

function isFriend($user, $friend) {
    $isFriend = false;
    $friends = getUsersFriends($user);
    foreach ($friends as $f) {
        if (in_array($friend, $f)) {
            $isFriend = true;
        }
    }
    return $isFriend;
}
Kevin

Just like the comments above, if $friends is indeed just a flat array, just use in_array alone. No need for foreach. What happens is, you're applying in_array of each string which doesn't make sense. You apply in_array to the whole array of strings:

function isFriend($user, $friend) {
    return in_array($friend, getUsersFriends($user));
}

Take note that Sanoj != sanoj. It might be better to change all the caps of the collection of friends to compare against the strtolowered $friend:

Idea:

function isFriend($user, $friend) {
    return in_array(strtolower($friend), array_map('strtolower', getUsersFriends($user)));
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Warning: mysql_error() expects parameter 1 to be resource, string given

分類Dev

android sent value to php(mysql_fetch_array() expects parameter 1 to be resource, array given in)

分類Dev

htmlspecialchars() expects parameter 1 to be string, object given for join query

分類Dev

unknow ERROR(in_array()は、パラメーター2が配列であり、文字列が指定されていることを想定しています)

分類Dev

Error: expects parameter 1 to be mysqli_stmt, boolean given?

分類Dev

mysql_query() expects parameter 2 to be resource, string given in /home/u921305435/public_html/phpinfo.php on line 9

分類Dev

PHP mysqli_query() expects parameter 1 to be mysqli, null given in

分類Dev

mysqli_query() expects parameter 1 to be mysqli, null given :(

分類Dev

PHPのin_arrayとStringには

分類Dev

"Type error: Argument 1 passed to Model::__construct() must be of the type array, string given, called in TechnicienController.php

分類Dev

How to enter a string to an array to a given position?

分類Dev

Javascript in_array

分類Dev

Using array of string with default parameter and overload procedure

分類Dev

LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

分類Dev

Pass array to async library eachSeries - expects 'Dictionary<{}>'

分類Dev

gson problems with empty array when it expects an object

分類Dev

Using in_array correctly with array inside array

分類Dev

PHP get possible string combination of given array which match with given string

分類Dev

Sort an array of objects based on a numeric key given as String

分類Dev

Is it possible to constrain the values of an array with Typescript to a given subset of string values?

分類Dev

get Array-Object-String thing from the given Object

分類Dev

in_array always returns false

分類Dev

Given an array A and m queries

分類Dev

Fill in values between given indices of 2d numpy array

分類Dev

2つの異なるサイズのin_array

分類Dev

Given a sorted array and a parameter k, find the count of sum of two numbers greater than or equal to k

分類Dev

array merge error from object string

分類Dev

How to post when post location expects data in array?

分類Dev

I meet an error with Material-UI and Mobx ,Error: Material-UI: capitalize(string) expects a string argument

Related 関連記事

  1. 1

    Warning: mysql_error() expects parameter 1 to be resource, string given

  2. 2

    android sent value to php(mysql_fetch_array() expects parameter 1 to be resource, array given in)

  3. 3

    htmlspecialchars() expects parameter 1 to be string, object given for join query

  4. 4

    unknow ERROR(in_array()は、パラメーター2が配列であり、文字列が指定されていることを想定しています)

  5. 5

    Error: expects parameter 1 to be mysqli_stmt, boolean given?

  6. 6

    mysql_query() expects parameter 2 to be resource, string given in /home/u921305435/public_html/phpinfo.php on line 9

  7. 7

    PHP mysqli_query() expects parameter 1 to be mysqli, null given in

  8. 8

    mysqli_query() expects parameter 1 to be mysqli, null given :(

  9. 9

    PHPのin_arrayとStringには

  10. 10

    "Type error: Argument 1 passed to Model::__construct() must be of the type array, string given, called in TechnicienController.php

  11. 11

    How to enter a string to an array to a given position?

  12. 12

    Javascript in_array

  13. 13

    Using array of string with default parameter and overload procedure

  14. 14

    LSTM network expects target at last layer to have 2 dimensions, but got array with shape (996, 1, 1)

  15. 15

    Pass array to async library eachSeries - expects 'Dictionary<{}>'

  16. 16

    gson problems with empty array when it expects an object

  17. 17

    Using in_array correctly with array inside array

  18. 18

    PHP get possible string combination of given array which match with given string

  19. 19

    Sort an array of objects based on a numeric key given as String

  20. 20

    Is it possible to constrain the values of an array with Typescript to a given subset of string values?

  21. 21

    get Array-Object-String thing from the given Object

  22. 22

    in_array always returns false

  23. 23

    Given an array A and m queries

  24. 24

    Fill in values between given indices of 2d numpy array

  25. 25

    2つの異なるサイズのin_array

  26. 26

    Given a sorted array and a parameter k, find the count of sum of two numbers greater than or equal to k

  27. 27

    array merge error from object string

  28. 28

    How to post when post location expects data in array?

  29. 29

    I meet an error with Material-UI and Mobx ,Error: Material-UI: capitalize(string) expects a string argument

ホットタグ

アーカイブ