How can using an array for user rights in addition to a user status integer in PHP applications provide more flexibility in managing user permissions?

Using an array for user rights in addition to a user status integer in PHP applications allows for more granular control over user permissions. By storing user rights as an array, you can easily add or remove specific permissions for each user without changing the underlying user status. This approach provides more flexibility in managing user permissions and simplifies the process of assigning and updating user rights.

// Define user status constants
define('USER_STATUS_NORMAL', 1);
define('USER_STATUS_ADMIN', 2);

// Define user rights as an array
$userRights = [
    'can_view_dashboard' => true,
    'can_edit_profile' => true,
    'can_post_comments' => false,
];

// Check user rights based on status and specific permissions
if ($userStatus === USER_STATUS_ADMIN || $userRights['can_view_dashboard']) {
    // User has permission to view the dashboard
    echo 'User can view dashboard';
} else {
    // User does not have permission to view the dashboard
    echo 'User cannot view dashboard';
}