Page 46 - Open Soource Technologies 304.indd
P. 46

Web Technologies-I



                   Notes         2.4.3 Operator Associatively
                                 Associatively defines the order in which operators with the same order of precedence are evaluated.
                                 For example, look at:
                                 2 / 2 * 2

                                 The division and multiplication operators have the same precedence, but the result of the
                                 expression depends on which operation we do first:
                                 2/(2*2) // 0.5 (2/2)*2 // 2

                                 The division and multiplication operators are left-associative; this means that in cases of ambiguity,
                                 the operators are evaluated from left to right. In this example, the correct result is 2.

                                 2.4.4 Operator Concept
                                 PHP has many types of operators. They can be categorized as:
                                    •  Arithmetic operators

                                    •  String concatenation operators
                                    •  Autoincrement and Autodecrement operators
                                    •  Comparison operators
                                    •  Bitwise operators
                                    •  Logical operators
                                    •  Casting operators
                                    •  Assignment operators
                                    •  Miscellaneous operators that do not really fit into any category.
                                 Arithmetic Operators

                                 The arithmetic operators are operators you will recognize from everyday use. Most of the arithmetic
                                 operators are binary; however, the arithmetic negation and arithmetic assertion operators are
                                 unary. These operators require numeric values. Non-numeric values are converted into numeric
                                 values by some rules. The arithmetic operators are:
                                 Addition (+)
                                 The result of the addition operator is the sum of the two operands.
                                 Subtraction (–)

                                 The result of the subtraction operator is the difference between the two operands; i.e. the value
                                 of the second operand subtracted from the first.

                                 Multiplication (*)
                                 The result of the multiplication operator is the product of the two operands. For example, 3 * 4 is 12.
                                 Division (/)

                                 The result of the division operator is the quotient of the two operands. Dividing two integers can
                                 give an integer (e.g. 4/2) or a floating-point result (e.g. 1/2).
                                 Modulus (%)

                                 The modulus operator converts both operands to integers and returns the remainder of the division
                                 of the first operand by the second operand. For example, 10 % 6 is 4.





        40                                LOVELY PROFESSIONAL UNIVERSITY
   41   42   43   44   45   46   47   48   49   50   51