Well here it is the key to loops :
Operators help the code to make decisions for the choice the visitor made without them there it would be really hard to make loops (for some things even impossible)
here is a link to show you how you use them:Operators Precedence
let's talk about the most used operators first:
1.) Comparison Operators
2.) Logical Operators
1.)Comparison Operators
here are all operators listed:
== equal
=== identical
!= not equal
<> not equal (is more good)
!== not identical (it's not used that much)
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
keep in mind that the equal operator(==) is not the same as the Assignment Operator (=)
let's try them out a bit
<?php
$a=10;
$b=25;
$c=25;
$d="25";
$x=$a == $b; // returns false because 10 is not equal to 25
$x=$b === $c; // returns true because $b and $c are both integers and have the same value
$x=$b === $d; // returns false because they have the same value but are not of the same type ($b is a integer ,but $d is a string)
$x=$a != $b; // returns true because 10 is not equal to 25
$x=$a <> $b; // returns true because 10 is not equal to 25
$x=$a < $b; // returns true because 10 is less than 25
$x=$a > $b; // returns false because 10 is not greater than 25
$x=$a >= $b; // returns false because 10 is not greater than or equal to 25
$x=$a <= $b; // returns true because 10 is greater than or equal to 25
?>
for more details check this out:
type comparsions
2.) Logical Operators
well most of the time you won't need just to compare two values to decide on one option and for that you have Logical operators
Here is the list of them:
AND
OR
XOR
NOT
the and operator has
two ways to write:
and
&&
keep in mind that they are not the same because they don't have the same priority check this out:Operators Precedence
just like the AND operator the OR operator has two ways to write:
or
||
keep in mind that they are not the same because they don't have the same priority check this out:
Operators Precedence
all the others just have one way to write them down
for XOR it's xor
and for the NOT operator it's the
! sign (remember him from the not equal operator? ;) )
Example Name Result
$a and $b And TRUE if both $a and $b are TRUE.
$a or $b Or TRUE if either $a or $b is TRUE.
$a xor $b Xor TRUE if either $a or $b is TRUE, but not both.
! $a Not TRUE if $a is not TRUE.
$a && $b And TRUE if both $a and $b are TRUE.
$a || $b Or TRUE if either $a or $b is TRUE.
Category:
Website Programming | Views: 2,212 | on: September 12, 2009 | by:
jooria