Constants Operators in PHP Constants The name allocated to a value is known as constant. The value is fixed and cannot be modified by the user. It is case sensitive. The name of the constant starts with a letter, following numbers, letters, or underscores. It is case sensitive. The following are examples of various PHP constants. Code: define( "NEW", "new value"); define( "OLD", "old value"); The define() function is useful for accessing values of the constant. There is no need for $ sign for a constant. User can read values to be retrieved from the name of the constant. The constant() function is used for accessing constants value. Only constant values are obtained. Distinguish between constant and variables The constants are defined and accessed in the program regardless of the scoping rules The dollar sign ( $ ) is not added before the constant but the variable contains a dollar sign. User cannot modify the constants in PHP The define() function is used for defining the constant values Various PHP constants There are several PHP predefined constants used for the execution of scripts. There are five constants which can be used appropriately. _FILE_ : The filename and full path of the file. The name of the file is returned. _LINE_: The line number of the file is returned _CLASS_: The class name declared by the user is returned _METHOD_: The class method name is described _FUNCTION_: The name of the function is defined Operators in PHP The operators in PHP are the one which are used for performing the operations on the operands. There are various types of PHP operators supported. Arithmetic operators Logical operators Comparison operators Assignment operators Conditional operators We shall explore about all these operators in detail. 1. Arithmetic operators The arithmetic operators perform operations like calculating numeric values, property and function calls, etc. The two values can be added using + operator and subtracted using – operator. The various arithmetic operators provided in PHP are as mentioned below: Addition: It is used for adding two operands. The + operator is used. Subtract: The second operand is subtracted from the first. The – operator is used. Multiplication: Used for multiplying both the operands. It is represented as *. Division: The numerator is divided by the denominator Modulus: The remainder after the integer division is performed Increment operator: Used for increasing the integer value by 1. It is defined as ++ Decrement operator: Used to decrease the integer value by 1. It is represented by --. Example to demonstrate the use of arithmetic operators Code: <?php echo ( 4 + 2 ). "\n"; echo ( 3 – 2). "\n"; echo ( 10 % 2). "\n"; ?> 2. Logical operators The logical operators work on Boolean values. They combine logical values and create a Boolean value. The various logical operators supported by PHP are mentioned below: And: It is true when both the arguments have value as true. Or: It is true when either of the arguments have value as true Xor: The value is true if either of the arguments have value as true Not: It holds the value true if the single argument has the value as false &&: The value is true if both the arguments have value as true ||: If either of the value is true, the result is true Example: Code: <?php $x = true && false; var_dump ( &x); $y = true || false; var_dump ( &y ); $z = false || false; var_dump ( &z); ?> 3. Comparison operators The comparison operators are used on strings and numbers. The list of comparison operators is as mentioned below: == : The value is true if the arguments are equal >: If the left argument is greater than the right, the result is true <: If the right argument is greater than the right, the result is true ! = : If the two arguments are not equal, the result is true < = If the left argument is less than or equal to the right, the value is true >= : If the right argument is greater than or equal to the right, the value is true Example: Code: <?php $x = 400; $z = "400"; var_dump ( $x == $y ); ?> 4. Assignment operators The assignment operators used in PHP are as mentioned below: = : The operator is used to assign the value from right operands to the left side operand -=: The subtract AND operator is used to the right operand from the left operand * =: The multiplication of right with the left operand is done and the value is added to the left operand /= : It divides the left operand and the value is assigned to the left operand %=: The modulus of using two operands and values is assigned to the left operand Example: Code: <? php $p = 5; $p += 4; $q = 6; $q -= 2; ?> 5. Conditional operators In conditional operators, the expression is calculated to a Boolean value and the further execution is dependent on the result of the calculation. It is denoted as ?:. If condition is True? Then value X: otherwise value Y. Operator Precedence The precedence of the operators is dependent on the expressions. The evaluation of the expression is useful. The operators in PHP has precedence. The operators with higher precedence is calculated first. The list of operators with their precedence are as mentioned below: Unary: The unary operators used in PHP are !, ++, --. The value is evaluated from right to left Multiplicative: The operators *, /, 5. The values are calculated from left to right Additive: The operators + and -. The values are calculated from left to right Relational: The operators < < = > > =. Evaluation from left to right Equality: The operators == , !=. The values are calculated from left to right Logical AND: The && operator is used. Calculated from left to right Logical OR: The || operator is used. Calculated from left to right Conditional: The ?: operator is used. Associativity from right to left Assignment: The operator =, +=, -=, *=, /=, %=. The associativity from right to left