Unexpected result with in_array() and multiple conditions in if expression
I have an if expression where I want to check some items in an array and
another variable. My original if expression was this:
if(!in_array($user->id, array($lsp->created_by_id,
$lsp->approving_committee_pri_id, $lsp->approving_committee_sec_id)) or
$user->level != 5)
{
$error[] = 'You do not have permissions to modify this.';
}
However, I'm not getting the desired results. Essentially, if the user's
id isn't in the array or the user's access level isn't equal to 5, then it
should populate the $error array. Even when I modify the database so the
user's id is in the array or his access level is equal to 5, it's still
populating the $error array.
I've had to modify my code to this for it to work, which is kind of the
opposite of my previous code:
if(in_array($user->id, array($lsp->created_by_id,
$lsp->approving_committee_pri_id, $lsp->approving_committee_sec_id)) or
$user->level == 5)
{
//does nothing
}
else
{
$error[] = 'You do not have permissions to modify this.';
}
What am I doing wrong? I want to do this in one line, but maybe I'm not
understanding something correctly. I'm using PHP 5.4.14. Thanks!
No comments:
Post a Comment