Operator in PHP
What is the operator? The simple answer from expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + are called operators.
What is the operator? The simple answer from expression 4 + 5 is equal to 9. Here, 4 and 5 are called operands and + are called operators. PHP language supports the following operator types:
- Arithmetic operator
- Comparison operator
- Logical operator (or relational operator)
- Assignment operator
- Conditional operator (or 3-star operator)
Arithmetic operators in PHP
The table below lists the arithmetic operators supported by the PHP language:
Suppose variable A holds value 10, variable B holds 20 then:
For example:
Operator Description Example + Add two operands A + B with the result 30 - Subtract the second operand from the first operand A - B resulting in -10 * Multiply the two operands A * B resulting in 200 / Division B / A result is 2% The balance of B% A result is 0 ++ The operator increases, adds the operand value an A ++ unit, the result is 11 - The operator decreases, decreases the value of the operand A unit A - the result is 9Comparison operators in PHP
The table below lists the comparison operators supported by the PHP language. Suppose variable A holds value 10, variable B holds value 20, then:
For example:
Operator Description Example == Check if 2 operands are equal or not. If equal, the condition is true. (A == B) is not true. ! = Check if two operands have different values. If not, the condition is true. (A! = B) is true. > Check if the left operand is greater than the right operand. If larger, the condition is true. (A> B) is not true. If it is smaller then true. (A = Check if the left operand has a value greater than or equal to the value of the right operand. If true, true. (A> = B) is not true. <= Check if the left operand is less than or equal to the right operand. If true, true. (A <= B) is true.Logical operators in PHP
The table below shows all logical operators supported by the PHP language. Suppose variable A has value 10 and variable B has value 20, then:
For example:
Operator Descriptionand Example Called Logic AND operator. If both operands are true, the condition becomes true (A and B) is true. or Called Logic OR operator. If one of the operands is true, the condition becomes true (A or B) is true. && Called the Logic AND operator. If both operands are true, the condition becomes true (A && B) is true. || Called Logic OR operator. If one of the operands is true, the condition becomes true (A || B) is true. ! Called Logic NOT operator. Use to reverse the logic state of operands. If the condition is true, the Logic NOT operator will result in false! (A && B) is false.The assignment operator in PHP
Here are the assignment operators supported by the PHP language:
For example:
Description OperatorExample = Simple assignment operator. Assign the right operand value to the left operand C = A + B to assign the value of A + B to C + = Add the operand value to the left operand and assign that value to the left operand C + = A is equal to C = C + A - = Subtract the operand value from the left operand and assign this value to the left operand C - = A is equivalent to C = C - A * = Multiply the price value the operand with the left operand and assign this value to the left operand C * = A which is equivalent to C = C * A / = Divide the left operand for the right operand and assign this value to the left operand C / = A is equal to C = C / A% = Taking the remainder of the left operand division for the right operand and assigning the left operand C% = A is equivalent to C = C% AConditional operator in PHP
There is more than one operator called conditional operator. First, it evaluates an expression to true or false and then executes either of the given commands depending on the outcome of the estimate. The conditional operator has the following syntax:
For example:
Operator Description For example? : Conditional expression If the condition is true? Then the value X: If not, the value YClassify operators in PHP
All of the above operators can be classified into the following types in PHP:
Unary operator, which precedes an operand.
The binary operator, receives two operands and performs various arithmetic and logical operations.
The ternary operator or the trin operator, receives three operands and estimates or the second or the third expression, depending on the estimated results of the first expression.
The assignment operator, which assigns a value to a variable.
Operator priority in PHP
Operator priority in PHP determines how the expression is calculated. For example, the multiplication operator takes precedence over the addition operator, and it is done first.
For example, x = 7 + 3 * 2; Here, x is assigned a value of 13, not 20 because the * operator has a higher priority than the + operator, so first it performs multiplication 3 * 2 and then adds 7.
The following table lists the priority order of operators in PHP. Operators with the highest priority appear at the top of the table, and the operators with the lowest priority are at the bottom of the table. In an expression, the highest priority operators are first calculated.
Type of deathUnited priority order! ++ - Right to left Multiplication * /% Left to right Addition + - Left to right Relationship <<=>> = Left to right Calculated = =! = Left to right Logic AND && Left to right Logic OR || Left to right Condition: Right to left Assign = + = - = * = / =% = Right to leftFollow tutorialspoint
Previous article: Constants in PHP
Next lesson: If, else, switch commands in PHP
You should read it
- Operator in C ++
- Boolean operators AND and OR in SQL
- ! = and! == What is the difference in JavaScript?
- C Shell operators
- Comparison operators in SQL Server
- Operator in JavaScript
- Load the stack of assignment operators in C ++
- Basic Shell operators
- Korn Shell Operator
- Overload binary operators in C ++
- The difference between the == and === operators in JavaScript
- Overload relational operator in C ++
Maybe you are interested
5 simple ways to help you remember everything in life 20 things to give up to be happier before the new year black hole, white hole, deep hole Detecting the tremors of the 'twin brothers' of the solar system, the key to deciphering early life 4 cosmic phenomena have the speed of traveling through the speed of light Science test: Potatoes can be grown on Mars