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
https://forums.phpfreaks.com/topic/61626-simplify-if-statement-not-working/
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?

 

 

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.

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.