Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数组函数中的php_Php_Arrays - Fatal编程技术网

数组函数中的php

数组函数中的php,php,arrays,Php,Arrays,我在数组()中使用,检查数组中是否存在值,如下所示, 但没有如预期的那样起作用: $projectId = $_GET['projectId']; $userId = $_GET['userId']; $qr2 = mysql_query("SELECT `userId`,`status` FROM `fndn_ProjectBacker` WHERE `projectId`='$projectId' && `status`='1'"); for($i = 1; $row2

我在数组()中使用
检查数组中是否存在值,如下所示, 但没有如预期的那样起作用:

$projectId = $_GET['projectId'];
$userId = $_GET['userId'];

$qr2 = mysql_query("SELECT `userId`,`status` FROM `fndn_ProjectBacker` WHERE `projectId`='$projectId' && `status`='1'");

for($i = 1; $row2 = mysql_fetch_assoc($qr2); $i++) {
    $arr1[$i] = array($row2);
}

if (in_array($userId, $arr1)) {
    echo "True";
}

请帮帮我

它不能按您的要求工作,因为您使用以下内容创建二维数组:

$arr1[$i]=array($row2);
        //^^^^^^     ^ See here
删除此处的数组声明,还可以使用while循环更改for循环,例如

while($row2 = mysql_fetch_assoc($qr2)){
    $arr1[] = $row2["userId"];
}

if (in_array($userId, $arr1)) {
    echo "True";
}


我还想欢迎您在2015年光临,并强烈建议您使用或,它们更安全。(另见:)

@fatemehnamkhaha什么是不工作?你有错误吗?将错误报告添加到文件顶部:
以及输出内容:
打印($arr1)在while循环之后?数组([0]=>Array([userId]=>0[status]=>1)[1]=>Array([userId]=>5[status]=>1)[2]=>Array([userId]=>25[status]=>1).@fatemehnamkha更新了我的答案。只需重新加载页面并重试代码。您只需要将userId添加到数组中。