Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:30:07+00:00 2026-05-14T06:30:07+00:00

$list_of_groups = array(FACULTY,STAFF); foreach ($list_of_groups as $i => $group) { $user_in_group = $adldap->user_ingroup($username,$group); print

  • 0
$list_of_groups = array("FACULTY","STAFF");

foreach ($list_of_groups as $i => $group) {
  $user_in_group = $adldap->user_ingroup($username,$group);
    print "<h2>Group: ".$group." user in group? ".$user_in_group."</h2>"; // if 1, means yes
}

Need to print run the appropriate function based on what returns true.

There are user’s that are members of both FACULTY and STAFF groups, so I want to check for those users and display the appropriate content for them.

So if the user is both faculty and staff, then display this, if they are only of staff, display that, same for faculty, might not make sense, but I will write out some code “in theory” that will help you understand what I am trying to do

switch(Get group membership of user) {
 case "FACULTY":
 print "Faculty group member";
 break;

 case "STAFF":
 print "Staff group member";
 break;

 case "FACULTY and STAFF":
 print "Member of both faculty and staff";
 break;
}

I am unsure on how it will check if they are members of both groups and run that thru the case statement to display the appropriate message.

The foreach look currently runs thru every group the user belongs to, prints out the ones from the $list_of_groups and the number 1 to the right of it, signifying they belong to it. The problem I have is trying to use that information to run thru the case statement, I am unsure of how to go about that.

This is what it prints out for the user currently passed thru the foreach loop:

Group: FACULTY user in group? 1
Group: STAFF user in group? 1

Any help is appreciated.

EDIT: I apologize, I did not explain well enough. I need to run thru all the groups they belong to, if they belong to both Faculty and Staff, print “Belongs to Faculty and Staff”, if only faculty print out “Faculty”, if only staff print out “Staff”, if only student, print out “Student”, this is for displaying certain information based on what group the user belongs to. So the code would have to check all groups, I guess the list_of_groups is not needed, as they will find the group membership via $result=$adldap->user_groups(“$username);.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:30:07+00:00Added an answer on May 14, 2026 at 6:30 am
    function getGroupMembership($username) {
        $list_of_groups = array("FACULTY","STAFF");
        $groups = array();
    
        foreach ($list_of_groups as $i => $group) {
            $user_in_group = $adldap->user_ingroup($username,$group);
            if ($user_in_group)
                $groups[] = $group;
        }
        return implode(' and ', $groups);
    }
    

    This will return a string as you requested for your switch. (Assuming user_ingroup returns 0 or false if the user is not in the group.)

    Addendum based on the edit:

    I’m assuming the array returned is of the form (“Group1″,”Group2″,”etc”) in no order. Swap it into a hash with true/false as values.

    function convertToHash($groups) {
        $hash = array();
        $foreach($groups as $group) {
            $hash[$group] = true;
        }
        return $hash;
    }
    

    Now use normal conditionals to check.

    if (isset($hash['Student']) and count($hash) == 1) {
       // just a student
    }
    else if (isset($hash['Student']) and isset($hash['Staff']) and count($hash) == 2) {
       // student and staff: whatever this means
    }
    else {
       // my method broke
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.