PHP Operators

There are many types of operators in PHP, those are:

• Assignment Operators for assigning data to variables
• Arithmetic Operators for performing basic math functions
• String Operators for joining two or more strings
• Comparison Operators for comparing two pieces of data
• Logical Operators for performing logical operations on Boolean values

In addition, PHP also provides:
• Bitwise Operators for manipulating bits using boolean math
• Error Control Operators for suppressing errors
• Execution Operators for executing system commands
• Incrementing/Decrementing Operators for incrementing and decrementing numerical values
• Type Operators for identifying Objects

Arithmetic Operators
Arithmetic operators allow you to perform basic mathematical operations:

Addition $a = 1 + 3.5;
Subtraction $a = 4 - 2;
Multiplication $a = 8 * 3;
Division $a = 15 / 5;
Modulus $a = 23 % 7;

Incrementing/decrementing operators are a special category of operators that make it possible to increment or decrement the value of an integer by one. They are unary operators, because they only accept one operand (that is, the variable that needs to be incremented or decremented), and are somewhat of an oddity, in that their behavior changes depending on whether they are appended or prepended to their operand.

The position of the operator determines whether the adjustment it performs takes place prior to, or after returning the value:

• If the operator is placed after its operand, the interpreter will first return the value of the latter
(unchanged), and then either increment or decrement it by one.
• If the operator is placed before the operand, the interpreter will first increment or decrement the
value of the latter, and then return the newly-calculated value.

Here are a few examples:

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...