By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,947 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Comparing Single Value to Multiple Values in Single Statement??

P: 56
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

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!

Nov 11 '07 #1
Share this Question
Share on Google+
1 Reply

Expert 5K+
P: 5,058
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");
  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. }
Which would math "Bob" and then stop.

Is this what you are looking for?
Nov 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.