Documentation

GetUserGroup

array
CUser::GetUserGroup(
 int id
)

The method returns an array of ID's of groups containing the user with the id. GetUserGroup receives data from the user records in the database. Static method.

Parameters

Parameter Description
id User ID.

See Also

Examples of use

<?
// obtain array of groups for user with ID=12
$arGroups = CUser::GetUserGroup(12);
echo "<pre>"; print_r($arGroups); echo "</pre>";
?>

Checking if the user is included into a group:

// for any user
echo in_array($group_id, CUser::GetUserGroup($user_id));

// for the current user
echo in_array($group_id, $USER->GetUserGroupArray());

Checking if the user is included into multiple specified groups:

<?$arGroupAvalaible = array(1,9,12,13,14,15); // array of groups to be checked for the user availability
$arGroups = CUser::GetUserGroup($USER->GetID()); // array of groups which include the user
$result_intersect = array_intersect($arGroupAvalaible, $arGroups);// further check if the user is a member of one of the groups minimum; or permitting the user to perform action
if(!empty($result_intersect)):     print "permitted granted to visit or view this part of the page";endif;?>


© «Bitrix24», 2001-2024
Up