0

I got an array $data['permissions'] which looks like this: Array ( [0] => 2 [1] => 11 ) and my in_array function I wrote do not work. Here is the code:

$data['permissions'] = $auth_user->getPermissions();
$stmt = $auth_user->runQuery("SELECT * FROM words;");
$stmt->execute();
while($wordsRow=$stmt->fetch(PDO::FETCH_ASSOC)){
                        echo $wordsRow['subcategory_id'];?>
                    <tr>
                        <?php
                        if($wordsRow['user_id'] == $_SESSION['user_session'] ||
                        in_array(array($wordsRow['subcategory_id']), $data['permissions'])){ ?>
                            <td><?php echo $wordsRow['name'];?></td>
                            <td><?php echo $wordsRow['subcategory_id'];?></td>
                            <?php
                        }
                        ?>
                    </tr>
                    <?php
                    }

$wordsRow['user_id'] == $_SESSION['user_session'] in if works fine but in_array function in if is not finding the value that actually is in this array.

echo $wordsRow['subcategory_id'];

in while loop shows: 11 2 11. Where is the problem?

0

1 Answer 1

2

The first parameter to in_array should be a value to find and you're passing it an array to find inside of a one-dimensional array which just isn't going to work.

Try changing this:

in_array(array($wordsRow['subcategory_id']), $data['permissions'])

To something like this:

in_array($wordsRow['subcategory_id'], $data['permissions'])
Sign up to request clarification or add additional context in comments.

1 Comment

Yeah. I guess I missed that becouse of copying parts of code. Just newby. Thank you very much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.