need help passing multiple variables from foreach loop to test in switch case statement
Posted
by Brad
on Stack Overflow
See other posts from Stack Overflow
or by Brad
Published on 2010-04-12T14:11:38Z
Indexed on
2010/04/12
14:33 UTC
Read the original article
Hit count: 430
$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.
© Stack Overflow or respective owner