I have an array of subscriptions/plans (access levels):
define('PLAN_A', 0); // 0001
define('PLAN_B', 2); // 0010
define('PLAN_C', 4); // 0100
define('PLAN_D', 8); // 1000
define('PLAN_E', 16); // 10000
A user can be subscribed to one or more plans.
$user_one = array(PLAN_A, PLAN_C); // is subscribed to two plans
$user_two = array(PLAN_C); // is only subscribed to one plan
A 'process' requires a certain subecription plan level - or multiple plan levels:
$process_1 = array(PLAN_B); // requires only PLAN_B subscripton
$process_2 = array(PLAN_B, PLAN_D); // requires either PLAN_B or PLAN_C subscription
I want to check if $user_one has the 'authority' to access $process_1, and separately check if $user_one has authority to access $process_2 . And do the same check for $user_two. ("Authority" is if the user has the subscription plan required by the process.)
It looks like I need to check if any user plan subscription (one or more) is contained in the subscription requirements of the processes.
I tried using bitwise checking (which is why the PLANs have binary values), but that will only work for the check of $process_1 . How do I check if $user_1 has access to $process_2 ? Or, how to check if any value of the user array is contained in any value of the process requirement array?