Register for your free account! | Forgot your password?

Go Back   elitepvpers > Blogs > manulaiko3.0
You last visited: Today at 23:36

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Rate this Entry

Programming in PHP - Comparation Operators

Posted 01/30/2015 at 16:07 by manulaiko3.0

Copy and paste from my website:

So, we’ve already seen Math Operators to do shit maths and Logical Operators, to choose something. Now we want to compare two things, how will we do it? With Comparations Operators (I don’t know english name so I’m sure it’s 100% wrong name).
There are 6 types of operators that can be used to compare things:
  • Equal
  • Not equal
  • Less
  • More
  • Less or Equal
  • More or Equal
Equal

Look at this code:
<?php $variable1 = 10; $variable2 = 10; $variable3 = $variable1 - $variable2; //Script ends here, it's not an error, PHP scrips doesn't needs "?>" at the end //of the script if there's nothing else in the file We want to check the value of $variable3 is 0, for that we will use == operator.
<?php $variable1 = 10; $variable2 = 10; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 == 0); //True because 10 (variable1) - 10 (variable2) = 0 Not Equal

Code:
<?php $variable1 = 10; $variable2 = 10; $variable3 = $variable1 - $variable2; We want to check the value of $variable3 is not 0, for that we will use != operator.
<?php $variable1 = 10; $variable2 = 10; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 != 0); //False because 10 (variable1) - 10 (variable2) = 0 Less

The code:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; Now we want to see if $variable3 is less than 5000, we will use the operator <:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 < 5000); More

The code:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; Now we want to see if $variable3 is more than 5000, we will use the operator >:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 > 5000); Less or Equal

The code:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; Now we want to see if $variable3 is less or equal than 5000, we will use the operator <=:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 <= 5000); More or Equal

The code:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; Now we want to see if $variable3 is more or equal than 5000, we will use the operator >=:
<?php $variable1 = 5321; $variable2 = 10351; $variable3 = $variable1 - $variable2; $booleanResult = ($variable3 >= 5000); And that’s all, you might noticed that the last 4 examples are copy & paste, well, I’m sorry but the thing is the same and I’ve just came home from school so I’m tired.
Nex chapter: Binary Operators (Yes, it will be boring, but you can skip it, it’s not used in not complex projects)
See you!
Posted in Uncategorized
Views 583 Comments 0 Email Blog Entry
« Prev     Main     Next »
Total Comments 0

Comments

 

All times are GMT +1. The time now is 23:36.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.