Reputation: 19
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?
Upvotes: 0
Views: 53
Reputation: 24661
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'])
Upvotes: 2