I have a database calls that is providing me a list of roles
that a user has access to on a specific page. There is a piece of logic that I am protecting using this permission data.
I am trying to figure out how to check if the role the user has exists in an array of allowed roles to see that data.
Example code:
$roles = ['User', 'Admin', 'HR'];
$userRoleFromDB = 'Admin';
...
// Check to see if the user has the Admin Role
<?php if (in_array($userRoleFromDB, $roles))){?>
Secret Stuff Here
<?php } ?>
While the above code works just fine if I am checking that the user has the Admin
role, I am trying to figure out how I can check multiple roles against an array.
$roles = ['User', 'Admin', 'HR'];
$userRoleFromDB = ['Admin', 'HR'];
...
// Check to see if the user has the Admin OR HR Role
<?php if (in_array($userRoleFromDB, $roles))){?>
Secret Stuff Here
<?php } ?>
Is there something similar to in_array
that can take two arrays for this check?