0

I have a simple php code :

<?php
$page = 2;
$max = $page * 10 + 1;
$min = $page - 11;
$counter = 1;

if($counter > $min && $counter < $max) // so, it will be if(1 > 9 && 1 < 20)
{
    echo "true!";
}
else
{
    echo "false!";
}
?>

If I run this code, It always echo true. However, If I change the assign like this :

$max = 21;
$min = 9;

The code work fine and echo false. Where did I wrong?

Edit : The code work fine if value of counter >= 9 :(

P/S : sorry for bad English.

1
  • You have to change your $counter to get a false response. Your $min is -9 and your $max is 21. So any value of $counter from -8 to 20 will return true, otherwise false. But with that kind of static values your question makes no sense. Commented Oct 24, 2015 at 2:11

2 Answers 2

1
$page = 2;
$min = $page - 11;

That means $min is -9, not 9.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, I see it. My bad :D
1

In your code, the line:

$min = $page - 11;

sets $min to -9, not 9 (because $page is 2).

Therefore, $counter > $min && $counter < $max would be true, because 1 > -9 AND 1 < 21.

1 Comment

Ah, I see it. My bad :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.