通过循环检查数组项的值

时间:2014-05-11 13:57:24

标签: php mysql

while ($row = $checkUser->fetch_assoc()) {
        $arr = $row['username'];
}

像这样检查只是不起作用

if($arr !="john"){

}else{

}

如何检查$ row ['username']是否包含字符串“john”?

1 个答案:

答案 0 :(得分:0)

假设你正确得到这个$row['username']。然后

$arr = array();

while ($row = $checkUser->fetch_assoc()) {
        $arr[] = $row['username'];
}

if(in_array("john",$arr)){
    //there is a username john in the array
}else{
    //this is no john inside the array
}