Jump to content

will OR , && work


desithugg

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?
Link to comment
https://forums.phpfreaks.com/topic/16707-will-or-work/
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
Link to comment
https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70204
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..
Link to comment
https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70208
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).
Link to comment
https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70212
Share on other sites

Archived

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

×
×
  • Create New...

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.