Jump to content

[SOLVED] [PHP] I don't understand this logic.....


Eowyne

Recommended Posts

Hi there,

 

I'm not new to PHP, I have been creating a lot of things since a year or 7 ago... but I can't help it to be not able to understand this logic which PHP gives me right now...

 

I have a, in my logic, pretty easy IF statement, Which has 4 conditions:

 

$a = 5;
$b = 1930;
$c = 1;

IF($a <= $c OR $a == 1930 AND $b <= $a OR $b == 1930){
echo "true";
}

 

which should read as:

 

IF(5 <= 1 OR 5 == 1930

AND 1930 <= 5 OR 1930 == 1930){ }

 

right?

 

Well, in my logic, $a is NOT Less or Equal to 5, or $a isn't 1930,

AND $b isn't Less or Equal to $a, but $b does equal 1930

 

So this gives me: False for the first section, and a True (or-section) of the second section,

however.. knowing that the statement should be both true for section one AND section two, this should give me FALSE as an outcome...

 

However, PHP says it's true...

 

What am I doing wrong? I'm staring myself blind at the moment..

 

 

Thanks in advance, Eowyne

 

Link to comment
Share on other sites

Wow.. this was way too easy to solve..............

 

Thnx rhodesa and Roopurt.. you both gave me the exact hints I needed to solve this utterly question..

 

it was just a manner of adding two ( and ) 's between both sections...

 

IF(($a <= $c || $a == 1930) && ($b <= $a || $b == 1930)){ 

 

This indeed gives me false, which I was hoping for ^^

 

I will bow my head in shame..

Link to comment
Share on other sites

And that is why I bow my head in shame.

 

It was way too easy to be go unnoticed, but as I said in my first post.. I've been staring myself blind upon that code, it seemed pretty logic to me, and it was logic, if you omit the () and you just keep on reading over it..

 

it happens, but I'm glad I've posted the question here :P It might have taken me longer to notice the brackets missing...

 

It's like staring at a letter with just one spelling-error, which you know is wrong, but you just don't notice it.. and somebody else reads it and notices it right away...

 

 

ps.... How do I mark this topic '[sOLVED]'? I can't edit my first post...

Link to comment
Share on other sites

<?php

$a = 5;
$b = 1930;
$c = 1;

IF($a <= $c OR $a == 1930 AND $b <= $a OR $b == 1930) {
echo "true";
}

?>

 

That is your code, that I executed, and it returned true... So, what was your problem? :P

Link to comment
Share on other sites

It had to return false :)

[/quote

 

Copied and pasted, didn't edit anything, and it echoes true. Have someone else test it. You may have your variables being reset somewhere or something, I have no idea, but it is true for me.

Link to comment
Share on other sites

Yeah, it returned true because the statement wás true, but I needed the statement to become false (e.g.

 

1 > 4 or 4 < 2 and 2 > 9 or 2 == 2 gives me true (2 equals 2), and due to me not placing () around the two sections, this is correct, but I needed it to return false:  e.g.: (1 > 4 or 4 < 2) and (2 > 9 or 2 == 2) --> False (section one gives false, section 2 true, false AND true = False)

 

So that's why it didn't work like it had to :)

(ps. I omitted the }else{echo "false";} statement)

 

 

and the reason Why I want it to become false..

I'm creating a scrolling-info bar, at which the admin should be able to start and stop the info shown at a set date (e.g.: it's 26-06-2008 now, and the admin wants the information to be shown only be shown today, so that's why he starts and stops the info at 26-06-2008.. which makes the info dissapear tomorrow (27-06-2008), when the statement returns false :P

 

It's all a part of a bigger thing, but it was just a silly, nitwit, mistake

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.