sKunKbad Posted July 24, 2007 Share Posted July 24, 2007 I've tried to simplify this if statement, but it doesn't work the ways I have tried: if ( (isset($_GET['Page']) && $_GET['Page'] > 1) || ($_GET['Action'] == 'CartAdd') || ($_GET['Action'] == 'CartGet') || ($_GET['Action'] == 'AddChoice') ){ echo "<meta name='robots' content='noindex,nofollow' />\n"; }else{ echo "<meta name='robots' content='index,follow' />\n"; } For example, I would think that this would be the same thing only simplified, but it doesn't work: if ( (isset($_GET['Page']) && $_GET['Page'] > 1) || ($_GET['Action'] == ('CartAdd' || 'CartGet' || 'AddChoice')) ){ echo "<meta name='robots' content='noindex,nofollow' />\n"; }else{ echo "<meta name='robots' content='index,follow' />\n"; } Anybody know what's wrong with this simplification? How should it be simplified? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 if (isset($_GET['Page']) && $_GET['Page'] > 1||$_GET['Action'] == 'CartAdd'||$_GET['Action'] == 'CartGet'||$_GET['Action'] == 'AddChoice'){ try Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 24, 2007 Author Share Posted July 24, 2007 Yes, that works, but why doesn't this part work: $_GET['Action'] == ('CartAdd' || 'CartGet' || 'AddChoice') Isn't it the same thing? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 24, 2007 Share Posted July 24, 2007 dude i dont see any language having this ('CartAdd' || 'CartGet' || 'AddChoice') even in java and c++ and etc . when you separate someting with || or && be sure that theres a condition to be satisfied no see yours ('CartAdd' || 'CartGet' || 'AddChoice') is there a condition that has been satisfy? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted July 24, 2007 Share Posted July 24, 2007 Comparasions are on a 1-1 level as teng said, you can't say <?php $fruit = "apple"; if($fruit != "orange" || "apple" || "grape"){ echo "good fruit!"; } else{ echo "bad fruit!"; } ?> even though it makes sense you can't do it however what you can do is use array and string comparisons to achieve this. Quote Link to comment Share on other sites More sharing options...
sKunKbad Posted July 25, 2007 Author Share Posted July 25, 2007 OK then, thanks for clearing that up for me. Quote Link to comment Share on other sites More sharing options...
ss32 Posted July 25, 2007 Share Posted July 25, 2007 you could try: if (in_array($_GET['action'], array("cartID", "cartGet", "addChoice"))) { //stuff } Quote Link to comment 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.