1. Home
  2. Knowledge Base
  3. PHP
  4. Less Than or Equal To, Greater Than or Equal To

Less Than or Equal To, Greater Than or Equal To

Change code:

$total_spent = 90;

to this:

$total_spent = 100;

Now run your code again. Did anything print?

The reason why nothing printed, and no errors occurred, is because we haven’t written any condition logic to test for equality. We’re only checking to see if the two variables are either Less Than ( < ) each other, or Greater Than ( > ) each other. We need to check if they are the same (as they now are).

Instead of adding yet another else if part, checking to see if the two totals are equal, we can use the operators <= (Less Than or Equal To) or >=(Greater Than or Equal To). Here’s how. Change this line in your code:

else if($total_spent < $discount_total) {

to this:

else if($total_spent <= $discount_total) {

The only thing that’s changed is the Less Than or Equal to symbol has been used instead of just the Less Than sign.

Now run your code again. Because we’re now saying “If total spent is Less Than or equal to discount total, then execute the code.” So the text gets printed to the screen.

Was this article helpful?

Related Articles