字符串不在数组中?

I'm having troubles with determining if someone is in an array or not:

<?php
    $depts = $db->query("SELECT depts FROM tbl_staff WHERE id = '".$_SESSION['exp_user']['userid']."'");
    $department = $depts->fetch_assoc();

    if (!in_array($forumdn['permissions'],$department)) {
           error_404("Permissions Violation");
           return;
    }

?>

The value of $forumdn['permissions'] given by var_dump is: string(1) "0"

The value of $department given by var_dump is:

array(1) { ["depts"]=> string(13) "0,1,2,3,4,5,6" }

Any ideas?

Try

$department = explode(',', reset($depts->fetch_assoc()));

without any other changes.

Does this do what you need? (I can't be certain because the question isn't worded very clearly to my eyes).

As I read it, the only problem is that $department is indeed an array, but not the array you want. So you have to isolate the first (and only) value in that array with reset (which gives the string "0,1,2,3,4,5,6") and then make that into the array 0 => 0, 1 => 1 etc (using explode) and then finally call in_array.

According to the results of your var_dump call, it looks like your results is an array with one string in it - all of the departments (comma separated). My suspicion is that you wanted to have the results end up being separated by commas as individual array elements (so, element 1 contains the value "13", elements 2 contains the value "14", etc). You can use explode for this:

$depts = $db->query("SELECT depts FROM tbl_staff WHERE id = '".$_SESSION['exp_user']['userid']."'");
$department = $depts->fetch_assoc();
$department = explode(",", $department);

Then your call to in_array should work dandy!

try :

if (!in_array($forumdn['permissions'], explode("," $department["depts"]))
{
    ....
}