Operators

The operators

are symbols that are used to manipulate variables. Operators are divided into:
1. The arithmetic operations that are used for numbers.
2. assignment for assigning a value to a variable.
3. bit operation,
4. comparisons necessary for conditional statements,
5. error checking,
6. execution used to run external programs,
7. increment and decrement,
8. logical
9. over

Arithmetic Operators

Example                Name                            Result
$ A + $ b              Addition                        Sum of $ a and $ b.
$ A – $ b                Subtraction                  Difference of $ a and $ b.
$ A * $ b               Multiplication              Product of $ a and $ b.
$ A / $ b               Division                         Quotient of $ a and $ b (without rest).
$ A% $ b              Modulus                         Remainder of division of a $ by $ b.

The assignment operator
The basic assignment operator is a symbol = ‚. Of course, this does not mean he is equal ‚. The expression $ b = 2 means that the variable $ b takes a value equal to 2. The variable can be assigned the value of another variable: $ b = 2; $ A = $ b; – $ A variable will be set to 2.
You can be attributed not only to specific values, but the values of other variables. These values can be attributed to cascade values attributed to be from right to left:

<? php
$ name = $ other_name = $ third_name = 2;
?>

All variable is assigned a value of 2.

The assignment operator can be combined with arithmetic operators and operator to concatenate strings:

example                 result
$ A + = 2                to the variable $ a is added 2
$ A – = 2                 From $ a will be deducted 2
$ A * = 2                $ a variable will be multiplied by 2
$ A / = 2                $ a variable added divided by 2
$ A% = 2                $ a variable takes the value of the remainder and by $ 2

 

Operators bit operation
Operators bit operation allows adjustment of the individual bits of variables.

Example                Name                       Result
$ a  & $ b             AND                          It sets the bits that are set in both variables.
$ a   | $ b           OR              bits are set, which are arranged in one or the other variable.
$ a ^$ b             XOR                            bits are set, which are arranged in one or the other                                                                        variable, but not both.
~ $ a                NOT                            inverter – are set bits are not set in the variable $ a                                                         and vice versa.

 

Comparison Operators
The comparison operators are required to use the conditional (if anything to do something). They return TRUE (true – 1) or FALSE (false – 0).

Example               Name                                 Result
$ a == $ b            Equal                                  True if $ a is equal to $ b.
$ a=== $ b          Identical                              True if $ a is equal to $ b and are of the                                                                                        same type.  (PHP4 only)
$ a! = $ b             Not Equal                            True if $ a is not equal to $ b.
$ a! == $b           Not identical                       True if $ a is not equal to $ b, or they are not                                                                                of  the same type. (PHP4 only)
$ a <$ b               Less                                        True if $ a is less than $ b.
$ a> $ b              Larger                                      True if $ a is bigger than $ b.
$ a <= $ b          Less than or equal to              True if $ a is less than or equal to $ b.
$ a> = $ b          Greater than or equal to          True if $ a is greater than or equal to $ b.

 

Increment and decrement operators
These operators are present in most programming languages. They are used to decrease or increase the value of a variable by 1. Each operator can be used in 2 ways: pre-increment / predecrement – first value of the variable is changed, and later returned, or post-increment / postdecrement – first, the return value is a variable, then the value of the variable will be changed.

Example                  Name                      Result
++ $ a              Pre-increment              increases $ a by one, then returns $ a.
$ a++              Post-increment             returns $ a, then increments $ a by one.
– $ a                 Predecrement              reduces by one, then returns $ a.
$ a-                    Postdecrement             returns $ a, then reduce the $ a by one.

Logical operators
Logical operators are used to build conditional statements – to combine several terms in one statement.

Example            Name             Result
$ a && $ b        AND               True if $ a and $ b are true
$ a || $ b           OR                 True if $ a and $ b are true
! $ a                   NOT              True if $ a is not true

Cookies help us deliver our services. By using our services, you agree to our use of cookies. More Info | Close