- Assignment Operators: assign values to variables and can also add to or subtract from a variable's current value.
- Arithmetic Operators: addition, subtraction, division and multiplication occur when these operators are used.
- Comparison Operators: compare 2 values and return either TRUE or FALSE.
- Logical Operators: determine the status of conditions.
- += "changes the values of a variable to current value plus the value on the right side".
- eg: $a +=3;
- -= "changes the value of a variable to the current value minus the value on the right side"
- eg: $a -=3;
- .= "concatenates (adds on to) the value on the right side with the current value".
- eg: $a .= "string";
Result :
ARITHMETIC OPERATORS:
simply perform basic mathematical tasks
- + "Adds values"
- - "Subtracts values"
- * "Multiplies values"
- / "Divides values"
- % "Returns the modulus or remainder".
Practical Example :
Results:
COMPARISON OPERATORS
- == " Equal to"
- != "Not equal to"
- > "Greater than"
- < "Less than"
- >= "Greater than or equal to"
- <= "Less than or equal to"
$a = 60; $b = 50;
// using (\$) to print a vairable with its dollar sign.
echo "Original number is: $a of \$a and $b of \$b ";
// == "is equal to"
if ($a == $b)
{ echo "TEST 1: \$a equals to \$b
"; } else {
echo "TEST 1: \$a does not equal to \$b
"; } // != "is not equal to" if ($a != $b) { echo "TEST 2: \$a does not equal to \$b
"; } else { echo "TEST 2: \$a equals to \$b
"; } //Greater than if ($a > $b) { echo "TEST 3: \$a is greater than \$b
"; } else { echo "TEST 3: \$a is not greater than \$b
"; } // Less than if ($a < $b) { echo "TEST 4: \$a is less than \$b
"; } else { echo "TEST 4: \$a is not less than \$b
"; } //Greater or equal to if ($a >= $b) { echo "TEST 5: \$a is Greater or equal to \$b
"; } else { echo "TEST 5: \$a is not Greater or equal to \$b
"; } // Less than or equal to if ($a <= $b) { echo "TEST 6: \$a is less or equal to \$b
"; } else { echo "TEST 6: \$a is not less or equal to \$b
"; } ?>
My results is shown on web browser:
LOGICAL OPERATORS
Allow our script to determine the status of conditions. In the context of if...else or while statements, it executes certain code based on which conditions are true and which are false.
At the moment, I have try my practical samples on && (and) and || (or) operators to determine the validity of a few comparisons.
My result on Firefox browser:
No comments:
Post a Comment