Basically, if this is NOT the case, then I need to throw an exception. So, I started off with something like:

if (
(isset($val1) && !empty($val1)) ||
(isset($val2) && !empty($val2)) ||
(isset($val3) && !empty($val3))
){
echo "We have a match";
}

That would ensure that at least one of the values is set but I need to know when only $val1 is set or when any combination of $val2 and $val3 are set.

I thought this would be a good way to try bitwise but I couldn’t get the answer that I wanted. I’ve ended up with a pseudo bitwise I guess, as follows:

Not exactly the way I wanted to do it, but it does work. I know there’s a better way and bitwise may be the way to go, so I’m interested in a) alternative solutions and b) the correct way to do this with bitwise.

Just re-read your previous post, I had misread it first time around. You’re suggesting that I set it up so that the values added to $sum will result in my matches failing if $sum > 4? Yes, that could work, but it’s still not truly bitwise, is it?

heh, SP let me blissfully edit my post while not showing your replies

basically, I don’t see your attraction to bitwise really, but based on the odd/even nature you posted, then & 1 (4&1 is 0, 3&1 is 1) will give you what you want if you convert the isset()'s to an integer using binary arithmetic.

it would seem that a smiple % 2 would be your answer, bitwise, if the least significant bit == 1 then it fails, so ! & 001

Not sure if I was confused before or it’s the wine I had with dinner, but my first interpretation was based on var1 being set, or either of the others -> x < 4 and > 0

> 4 could be 5, 6 or 7. The only acceptable one of these is 6
= 4 is acceptable
< 4 could be 1, 2 or 3. 1 and 2 are acceptable, 3 is not

So we can’t say > or < anything is acceptable. However, using bitwise operators ^ (XOR), | (OR) and & (AND) rather than the usual PHP || and &&, I would say something like:

$sum MUST be equal to $val1 ^ ($val2 | $val3)

Meaning, if $sum == $val1 then neither $val2 or $val3 must be set, because it’s an exclusive-or (XOR). If however $sum != $val1, then $sum must be equal to $val2 or $val3 or both.

That’s how I understand it, though I may have written it incorrectly. It’s just how to actually implement this in PHP that I’m stuck with

$sum = 0;
if(isset($v1)) $sum += 4
if(isset($v2)) $sum += 2
if(isset($v3)) $sum += 1
// > 4 means 1 and (2 or 3) isset
// = 4 means 1 only
// < 4 means 2 or 3 only

Edit, after I realised that “Not sure I quite follow you” was referring to you, it would seem that a smiple % 2 would be your answer, bitwise, if the least significant bit == 1 then it fails, so ! & 001

[QUOTE=hash;]Actually category c
I had a little fun working with bits (been a while since I’ve done that), and you learned how to phrase questions, and hopefully what bitwise means :)[/QUOTE]Lost me on that one. I thought the question was phrased perfectly OK, and I know what bitwise is. You should lay off the wine at dinner time

OK, I’m off with that one, you specifically asked for an alternate solution to one you already had that worked, and specified bitwise. Obviously I keep getting it wrong, so nn

Ha ha, no, I meant that I was looking for both alternatives in how to smoothly perform the same validation without bitwise, but also how to do it WITH bitwise. So I’ve now got a simple, logical method to validate the variables, which meets one of my criteria, and I’m happy with that, but I would still like to better understand whether I can use bitwise or not in order to get the same result