lefthow.blogg.se

Php operators
Php operators






php operators

The result on the variable is the same whichever is used. : This operator works the same as ++ but decreases the value by 1 instead of increasing by 1.īoth of these operators can be used either before or after a variable.

php operators

On the right, it will return the content of the variable, and after that increase it by 1. ++: This operator on the left of the variable will increase the variable by 1, and then return the result. Combined operators are:Īnother common operation is to increment or decrement a variable by one. You can combine an arithmetic operator with the assignment operator to form a combined operator. These operations can be shortened with the combined assignment operators. Combined Assignment OperatorsĪ common use of the assignment and arithmetic operators is to operate on a variable and then to save the result back into that same variable. If other considerations are equal, PHP goes from left to right. You can change the order in which the arithmetic is performed by using parentheses. PHP does multiplication and division first, followed by addition and subtraction.

php operators

$x = 4 % 2 // 0 modulus (division remainder)Įxponentiation operator (**) raises the first operand to the power of the second. The arithmetic operators include the four basic arithmetic operations - Addition, subtraction, multiplication, and division (+, -, *, and /) and the modulus operator (%) that gives the remainder of the division of two operands. This means that the operand to the left of "=" gets set to the value to the right of "=". The basic assignment operator in PHP is " =". The assignment operator assigns a value to a variable. Operators expect expressions of a specific type, for example, arithmetic operators expect either integers or floats. Variables, numbers, or text are examples of expressions. An expression is almost anything that has a value. Operators are symbols that take some expressions, operands, and perform mathematical or logical actions on them to get a result.








Php operators