Jump to content

Simplify IF statement not working


sKunKbad

Recommended Posts

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?

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.