Посмотрите на: Битовые операторы
С этим вы можете сделать что-то вроде (знайте, что это очень простой пример!):
<?php
// example actions
$actions = array(
'create' => 1,
'read' => 2,
'update' => 4,
'delete' => 8,
);
// example groups
$groups = array(
// Admins
2 => $actions['create'] ^ $actions['read'] ^ $actions['update'] ^ $actions['delete'],
// Moderators
3 => $actions['create'] ^ $actions['read'] ^ $actions['update'],
// Process Orders
4 => $actions['read'] ^ $actions['update'],
);
// example users
$users = array(
// Admin
(object)array(
'id' => 1,
'groupId' => 2,
),
// Moderator
(object)array(
'id' => 2,
'groupId' => 3,
),
// Process Order
(object)array(
'id' => 3,
'groupId' => 4,
),
);
foreach ($users as $user) {
if (isset($groups[$user->groupId])) {
printf('User: %s is allowed to: ' . "\n", $user->id);
if ($groups[$user->groupId] & $actions['create']) {
echo ' create';
}
if ($groups[$user->groupId] & $actions['read']) {
echo ' read';
}
if ($groups[$user->groupId] & $actions['update']) {
echo ' update';
}
if ($groups[$user->groupId] & $actions['delete']) {
echo ' delete';
}
echo "\n\n";
}
}