Jump to content

Archived

This topic is now archived and is closed to further replies.

desithugg

will OR , && work

Recommended Posts

umm i want to check if the user visiting the page has 2 character
1 male/trans
1 female/trans
and only continue if the user owns one of those character
[code]<?php if ($char1 == "Male" && $char2 == "Female" OR $char1  == "Male" && $char2 == "Trans" OR $char1 == "Female" && $char2 == "Male" OR $char1 == "Female" && $char2 == "Trans" OR $char1 == "Trans" && $char2 == "Male" OR $char1 == "Trans" && $char2 == "Female" OR $char1 == "Trans" && $char2 == "Trans")
{
echo"You have a pair.";
}
?>[/code]

will this work?

Share this post


Link to post
Share on other sites
[quote]i want to check if the user visiting the page has [b]2[/b] character ... and continue if the user owns [b]one[/b] of those character[/quote]

That's less than clear. Care to elaborate?

Share this post


Link to post
Share on other sites
you need extra braces i beleave

[code]<?php if (($char1 == "Male" && $char2 == "Female") OR ($char1  == "Male" && $char2 == "Trans") OR ($char1 == "Female" && $char2 == "Male") OR ($char1 == "Female" && $char2 == "Trans") OR ($char1 == "Trans" && $char2 == "Male") OR ($char1 == "Trans" && $char2 == "Female") OR ($char1 == "Trans" && $char2 == "Trans"))
{
echo"You have a pair.";
}
?>[/code]

AndyB I think that he has some kinda game script or sumet and he wants to check if they have 2 diffrent variables selected which means they make up a pair..

Regards
Liam

Share this post


Link to post
Share on other sites
lol sorry if i wasnt clear enough i just wanted to make sure that "OR" works in php not only querys.But it does work thanx

Share this post


Link to post
Share on other sites
OR is the same as ||, AND is the same as &&, bitwise or (|) bitwise and (&)

P.S.: can someone tell me what the & does when used in one of the following ways:

$Var &= $Var2; // object or something?
function myfunction(&$var); // Here, i believe you need to provide an already declared variable

if you know also otherways the & can be used, please let me know..

Share this post


Link to post
Share on other sites
When used thus: "myfunction(&$var);" you are passing a reference to the variable, not a copy of it.  Which means that if the function alters the value, the original variable gets altered and stays altered after the function returns, rather than a copy of the variable being altered and then thrown away when the function returns.

I guess "$var &= $var2" would logically and the values and stored the result in $var, so if they were 195 (binary 11000011) and 144 (binary 10001000) the result would be 128 (binary 10000000) but I've never used it in PHP (and seldom in C).

Share this post


Link to post
Share on other sites
Sample "bitwise and"

[code]<?php
$var1 = 7;
$var2 = 3;

echo '<pre>';
printf ('%08s<br>%08s', decbin($var1), decbin($var2) );
echo '</pre>';

$var1 &= $var2;

echo "7 &amp; 3 = $var1";
?>[/code]

Share this post


Link to post
Share on other sites
Yes. If you run the snippet you get
[pre]00000111
00000011
7 & 3 = 3[/pre]

Share this post


Link to post
Share on other sites
Should do.

Once you get your head around this binary malarky you can say to people things like "I'll be with you in 3 or 4 minutes" and what they don't realize is that actually gives you seven minutes.....

Share this post


Link to post
Share on other sites
Converstional language is very lax when it comes to logic. People often specify something like "The query should select two records, where the id is 1 and the id is 2"

Share this post


Link to post
Share on other sites
yeah, the only problem is my native language is dutch, so i can not use the bitwise or, and it would look silly, when your suddenly start talking english ;D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.