desithugg Posted August 6, 2006 Share Posted August 6, 2006 umm i want to check if the user visiting the page has 2 character 1 male/trans1 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? Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/ Share on other sites More sharing options...
AndyB Posted August 6, 2006 Share Posted August 6, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70200 Share on other sites More sharing options...
hackerkts Posted August 6, 2006 Share Posted August 6, 2006 It should works. Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70203 Share on other sites More sharing options...
shocker-z Posted August 6, 2006 Share Posted August 6, 2006 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..RegardsLiam Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70204 Share on other sites More sharing options...
desithugg Posted August 6, 2006 Author Share Posted August 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70205 Share on other sites More sharing options...
shocker-z Posted August 6, 2006 Share Posted August 6, 2006 || also works as an OR Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70207 Share on other sites More sharing options...
ignace Posted August 6, 2006 Share Posted August 6, 2006 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 variableif you know also otherways the & can be used, please let me know.. Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70208 Share on other sites More sharing options...
king arthur Posted August 6, 2006 Share Posted August 6, 2006 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). Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70212 Share on other sites More sharing options...
Barand Posted August 6, 2006 Share Posted August 6, 2006 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 & 3 = $var1";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70214 Share on other sites More sharing options...
ignace Posted August 6, 2006 Share Posted August 6, 2006 @Barand echo "7 & 3 = $var1"; // Gives 3 right? Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70220 Share on other sites More sharing options...
Barand Posted August 6, 2006 Share Posted August 6, 2006 Yes. If you run the snippet you get[pre]00000111000000117 & 3 = 3[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70224 Share on other sites More sharing options...
king arthur Posted August 6, 2006 Share Posted August 6, 2006 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..... Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70225 Share on other sites More sharing options...
Barand Posted August 6, 2006 Share Posted August 6, 2006 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" Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70234 Share on other sites More sharing options...
ignace Posted August 6, 2006 Share Posted August 6, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/16707-will-or-work/#findComment-70236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.