Connecting Tech Pros Worldwide Forums | Help | Site Map

Comparing Single Value to Multiple Values in Single Statement??

jenkinsloveschicken's Avatar
Member
 
Join Date: Dec 2006
Posts: 56
#1: Nov 11 '07
Is it possible to compare a single value to many in a single statement? Here is what I am attempting to do:

1. Users lands on page and via a cookie check function they are identified.
2. A query is sent to the headcount table to determine their Skill Type which also serves as the security level access identfier in this case.
3. Send the Skill Type to a function that will determine what table of reporting links they are authorized to view.

At this point I have a problem. I have basically two groups of skill sets, and two sets of reports, one for each level. There are three skill types for each group. Can I compare each set as a group(array) without having to write individual ElseIF or CASE statements?

For example, set one would be comprised of:
Skill Type
--------------
Director
Operations
Support

In the receiving function can I compare the Skill Type passed from the original page to a group of values with the same result? Kind of like an IN statement in SQL if that makes this more clear.

I hope that gives a good explanation of what I am trying to accomplish. I am attempting to avoid unneccessary code duplication if possible.

Thanks in advance!

-Jenkins

Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,751
#2: Nov 11 '07

re: Comparing Single Value to Multiple Values in Single Statement??


Hi Jenkins.

I'm not sure I entirely got the point, but I'll still try :)

Consider this code:
Expand|Select|Wrap|Line Numbers
  1. $first = array("John", "Mark", "Bob");
  2. $second = array("Jenkins", "Bob", "Mary");
  3.  
  4. foreach($first as $_v1) {
  5.   foreach($second as $_v2) {
  6.     if($_v1 == $_v2) {
  7.       echo "We got a match: {$_v1}";
  8.       break;
  9.     }
  10.   }
  11. }
  12.  
Which would math "Bob" and then stop.

Is this what you are looking for?
Reply